views:

234

answers:

2

Hi,

The issue I'm having is that I need to compile my code using specific libraries that are in different path locations. I need to use -lncurses library from ./ramdisk/libs path, the problem is that this directory also cointains a version of lthr library that I don't want to be linked. The makefile is pulling both libraries from the same location which is not what I what. I can't chage the contents of these library directories in the filesystem, so I need to find a way to tell the Makefile to link lncurses library from path A and link lthr library from path B instead using the lthr in path A.

Any suggestions? CC=icc NCE=-L./ramdisk/libs CFLAGS+=-I$(ROOTDIR)/../../include

LDFLAGS=-static -lthr

$(DESTDIR)/nce: nce mkdir -p $(DESTDIR) $(INSTALL) -m 777 nce $(DESTDIR)

nce: nce.c $(CC) $(CFLAGS) nce.c $(LDFLAGS) -o nce -lthr $(NCE) -lncurses

+1  A: 

You can (probably) bypass the search by giving the full path to the library archive. So instead of specifying -lncurses, you might try ./ramdisk/libs/libncurses.a (or whatever). You didn't specify whether it was a shared lib or not, and I'm not entirely sure that this works for shared libraries, but probably worth a try.

[edit]

Since this is a shared lib issues, maybe something like:

CC=icc
THR=/full/path/to/wherever/libthr/lives
NCE=/full/path/to/ramdisk/libs
CFLAGS+=-I$(ROOTDIR)/../../include
LDFLAGS=-static

nce: nce.c
    $(CC) $(CFLAGS) nce.c $(LDFLAGS) -o nce -L$(THR) -W,-rpath=$(THR) -lthr -L$(NCE) -W,-rpath=$(NCE) -lncurses

I'm kind of shooting in the dark here as I'm not familiar with icc, but the idea is to make sure the linker puts thr's path on the runtime linker's search path before the one on the ramdisk so that thr gets found there first.

kwatford
It's a pretty relevant aspect of the problem. The paths to shared libraries are principally resolved at runtime. (and can be influenced using `LD_LIBRARY_PATH`). As *Beta* suggested, it's a linker problem rather than a Makefile problem.
Michiel Buddingh'
so I trying with this, NCE=-L./../../ramdisk/lib/libncursesw.so.7 $(CC) $(CFLAGS) nce.c $(LDFLAGS) -o nce -lthr $(NCE)It didn't work al the references I made to lncurses library are not linked,nce.c:(.text+0x729): undefined reference to `initscr':(
Oliver
@Oliver: Don't use the `-L` there. That specifies a directory to be searched for libraries. Just put it straight in there, as in `NCE=./../../ramdisk/lib/libncursesw.so.7`The .so indicates this is a shared library, so this might not work properly anyway. I'll edit my answer and add something else you might try...
kwatford
Thanks for your advice guys, finally I could go throught this issue.thanks to kwatford for your advice I remove the -L and point directo to libncurses.a (.so.7 was wrong) it compiled and linked without any warning/error. I really appreciated you guy took the time to read my post :)
Oliver
@Oliver: Good to hear. Don't forget to mark the question as answered ;)
kwatford
A: 

You could copy the remote library to a local working directory.

ncurses would source from one location while thr would source from another.

Cheeso