Sponsored Content
Top Forums UNIX for Advanced & Expert Users Why LD_LIBRARY_PATH did not work but LDFLAGS did? Post 303032555 by bakunin on Wednesday 20th of March 2019 10:28:43 AM
Old 03-20-2019
Quote:
Originally Posted by colt
Then I passed the location of ncurses "lib" dir to LD_LIBRARY_PATH and exported it. It did not work, lynx configure was not able to find it. Then I decided to use LDFLAGS=-L'..../ncurses/lib/'. And it did work! The question is.......why? What LDFLAGS does that LD_LIBRARY_PATH does not? Thanks for your time
Obviously the environment variables LDFLAGS and LD_LIBRARY_PATH serve similar but different purposes. The way you used them both tell some (part of the) system to look in a certain list of directories to find something the respective part of the system looks for. So far, they are similar and hence work similarly. But the parts of the system they address are different and this is why the one "worked" and the other "didn't" - both actually worked, but you needed the part of the system addressed by the one and therefore the other had no effect.

LD_LIBRARY_PATH tells the runtime environment where to look for (dynamically linked) libraries. When you compile a (C) program it will consist of a main() function and many other functions. Each of these are first compiled into "object code". This is what the compiler does. Then these objects are picked up by the linker (more precisely "linkage editor") and are bound together to the final executable. This can be done by either putting all the objects together statically ("static linking") which will make the executable independent of external libraries but will make the functions available only within the executable. The executable can also be linked "dynamically" which means that some functions may still be included within the executable but some may be put into a separate library instead or they may even be provided from such a library so that there is no source code (and no object code) within the programs source to begin with. The advantage is that you can (re-)use already available functions without having to write them and other programs can use these functions too but it also makes the executable dependent on the availability of these external libraries from which the functions are being loaded at runtime.

Where these libraries exactly are (typically /usr/lib, /usr/local/lib, etc.) will be determined by the environment variable LD_LIBRARY_PATH (the Linux variant, the "LD" actually stands for "dynamic loader") or LIBPATH (the UNIX variant) and from a practical POV it is sensible to set both variables and set them to the same value. If either one is required it will work.

After this, now for the LDFLAGS variable: the LDFLAGS variable is used by the cmake utility to set the flags for the linker. So, basically what you did by:

Code:
LDFLAGS=-L'..../ncurses/lib/'

was to tell cmake that whenever the linker was called during the make process it should add -L'..../ncurses/lib/' to the commandline in addition to all the things already placed there by various other means. The role of LDFLAGS in this regard is similar to that of CFLAGS which sets additional flags for every call of the compiler. Note that both LDFLAGS as well as CFLAGS can put any other flag onto the commandline of their respective utility, not just the location of libraries.

I suggest to read the man pages of make (i.e. the cmake variant), the C-compiler of your choice (probably gcc, but then there are others too), the linkage editor you use, etc., for a list of available flags.

Also notice that there are similar variables (also called "macros") for other tools:

Code:
CFLAGS          C compiler
CPPFLAGS        Preprocessor
CXXFLAGS        C++-compiler
LDFLAGS         linker

I hope this helps.

bakunin
These 4 Users Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

cc, setuid, and LD_LIBRARY_PATH

Hi, This question deals with Solaris 2.8 and setuid programs. From research I've done so far, setuid programs ignore LD_LIBRARY_PATH; I've proven this and am OK with it. The thing I am not certain of how the C compiler is supposed to behave when it is invoked via a setuid program. Basically,... (0 Replies)
Discussion started by: WolfBoy
0 Replies

2. UNIX for Dummies Questions & Answers

Bash LD_LIBRARY_PATH?

Hello I have just tried to install ns-allineone-2.31 on cygwin cygwin is using the bash shell it asks for somethings to be put into the LD_LIBRAY_PATH, here is a snippet of what it says. (1) You MUST put /home/Chris/ns-allinone-2.31/otcl-1.13, /home/Chris/ns-allinone-2.31/lib, into your... (1 Reply)
Discussion started by: bysonary
1 Replies

3. UNIX for Dummies Questions & Answers

Ld_library_path

Hi, can anyone explain this terrm? should we setup it ? Thanks (1 Reply)
Discussion started by: ccp
1 Replies

4. HP-UX

SHLIB_PATH or LD_LIBRARY_PATH

hi Im using HP-UX 11i,PARISC .... Where do i find SHLIB_PATH or LD_LIBRARY_PATH , i couldnt find in env, listing...... Moreover im trying to execute file its throwing me error usr/lib/dld.sl: Can't find path for shared library: libgcc_s.sl /usr/lib/dld.sl: No such file or directory... (3 Replies)
Discussion started by: vasanthan
3 Replies

5. Solaris

setenv: cannot add the LD_LIBRARY_PATH

Hi all! I need to add new environment variable. e.g. # setenv LD_LIBRARY_PATH "/usr/ucblib:" # I check:# env LD_LIBRARY_PATH=/usr/ucblib: After rebooting I don't see this variable. Why don't save this variable? Thanks. (5 Replies)
Discussion started by: wolfgang
5 Replies

6. Solaris

Help with LDFLAGS options

Hi, We currently have a Makefile which has the following option in LDFLAGS: LDFLAGS_solaris= -G -library=%none Can anyone please help on what the significance of -library=%none is ? Thanks in advance. (1 Reply)
Discussion started by: jkbuilds
1 Replies

7. Shell Programming and Scripting

updating LD_LIBRARY_PATH

Inside my csh script, I have the following command: source ${HOME}/.login When I execute my csh script, why do I get the following error message: /cygdrive/c/WINDOWS/system32/export: Permission denied This is what I have inside my .login #!/bin/bash export... (9 Replies)
Discussion started by: casau
9 Replies

8. AIX

Set LD_LIBRARY_PATH to 1 or empty

I have a question on setting environmental variable LD_LIBRARY_PATH. The case is that, i cannot execute wget on my AIX machine. It return the following error: exec(): 0509-036 Cannot load program wget because of the following errors: 0509-022 Cannot load module... (5 Replies)
Discussion started by: cstsang
5 Replies

9. Shell Programming and Scripting

Ld_library_path

Hi., Currently my LD_LIBRARY_PATH setting is, LD_LIBRARY_PATH=/opt/app/product/11.2.0/client_1/lib Now, I need to append the JAVA to this setting... Can I set this way, Please suggest. ... (4 Replies)
Discussion started by: nuthakki
4 Replies

10. Shell Programming and Scripting

Problem with LD_LIBRARY_PATH

I am on Solaris . I have written a script callled T_1.sh #!/bin/sh ######################################################################################################## # # Source borne shell env.This is required for crontab to work as bip.sh uses environmental variables.... (24 Replies)
Discussion started by: rafa_fed2
24 Replies
All times are GMT -4. The time now is 01:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy