Passing environment variables in GNU Make (13)

1 Name: #!/usr/bin/anonymous : 2008-01-11 17:01 ID:WUg1DH7c

Hi

I am a user without root privileges that is compiling a library and program to be linked with the library using GNU Make invoked from tcsh on FreeBSD.

The problem i have is that i must myself manually set LD_LIBRARY_PATH in tcsh with setenv for the program to link properly with the library. I wish for make to do this somehow when it executes the linker commands.

So far i have not been able to figure out how, even though i have used things like passing variable declarations on the command line to make, and export.

2 Name: #!/usr/bin/anonymous : 2008-01-11 17:41 ID:Heaven

You're going to have to explain what exactly your problem is. If you know what to do, why not just do that?

3 Name: #!/usr/bin/anonymous : 2008-01-11 17:47 ID:WUg1DH7c

The problem i have is that i must myself manually set LD_LIBRARY_PATH in tcsh with setenv for the program to link properly with the library. I wish for make to do this somehow when it executes the linker commands.

4 Name: #!/usr/bin/anonymous : 2008-01-11 17:57 ID:Heaven

>>1 LD_LIBRARY_PATH doesn't control ld but the dynamic linker. What exactly did you type, what exactly did it print out?

5 Name: dmpk2k!hinhT6kz2E : 2008-01-11 17:59 ID:Heaven

You could prefix the linker command with the environment variable (in Bourne shell it'd be something like):

LD_LIBRARY_PATH=/usr/local/lib ld -o ...

In the case of GCC you can also use -L to set the library paths and -o to make it do the linking automatically:

gcc ... -L /usr/local/lib -o ...

Similar applies to ld actually:

ld ... -L /usr/local/lib -o ... 

6 Name: #!/usr/bin/anonymous : 2008-01-11 18:08 ID:WUg1DH7c

Yeah you can set the library path with -L but if the path is a non-standard path it wont work when the program is linked.

So far i've been using gcc to compile and ld to link in my Makefile, i guess i could try doing it both with gcc and see if there is a difference.

Basically the problem is that i want make to automatically compile and link a program and a library in a non-standard path, so no root privileges are allowed.

I can do it just fine but only if i setenv LD_LIBRARY_PATH in tcsh, in other words use MY shells program. So it's not portable to other shells. That's why i wanted to find out if there was a way for GNU Make to pass LD_LIBRARY_PATH to the linker for when the program is linked to the recently compiled library.

7 Name: #!/usr/bin/anonymous : 2008-01-11 20:45 ID:WUg1DH7c

I just remembered that i already use gcc to compile and link the program executable so that wont help.

The only thing so far that helps is to set LD_LIBRARY_PATH in my shell and that's what i don't want to do.

$(CC) $(LDFLAGS) $(CFLAGS) $(INCLUDES) $(LIBS) -o ../bicebot bicebot.c

8 Name: dmpk2k!hinhT6kz2E : 2008-01-11 22:05 ID:Heaven

> Yeah you can set the library path with -L but if the path is a non-standard path it wont work when the program is linked.

Are you sure? I'm fairly certain I've used it for just that in the past.

9 Name: #!/usr/bin/anonymous : 2008-01-11 22:50 ID:WUg1DH7c

I wish i was wrong but i tried that and while the linking goes on without any errors you can't run the program because it says the library can't be found. Also when you do ldd program you see that after your library it says (not found).

If there is a way to avoid this for libraries in non-standard locations, i sure want to know, because right now i can't even EXECUTE my program linked to this library without setting LD_LIBRARY_PATH first.

10 Name: #!/usr/bin/anonymous : 2008-01-12 01:05 ID:1ddx106R

>>6 You want what's called -rpath Usually something like this works:

gcc -Xlinker -rpath -Xlinker /path/to/target/dir $(LDFLAGS) $(CFLAGS) $(INCLUDES) $(LIBS) -o ../bicebot bicebot.c

11 Name: #!/usr/bin/anonymous : 2008-01-12 02:47 ID:Heaven

Wouldn't it be a whole lot easier to just link your library statically and not dynamically?

12 Name: #!/usr/bin/anonymous : 2008-01-12 10:00 ID:WUg1DH7c

>>11
That would be acceptable, thanks for the hint.

>>10
I'll try that, thank you.

13 Name: #!/usr/bin/anonymous : 2008-01-12 15:09 ID:WUg1DH7c

>>10
Thanks again, using rpath solved my problems.

Here is the 'project' btw, just something i did for fun but it was the first time i ever had to use GNU Make for real.

http://code.google.com/p/bicebot/

This thread has been closed. You cannot post in this thread any longer.