Oliver
Oliver

Reputation: 31

How to do a Makefile using a specific libraries in different paths?

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 want. I can't change 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 from 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

Upvotes: 3

Views: 5838

Answers (2)

kenm
kenm

Reputation: 23905

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.

Upvotes: 2

Cheeso
Cheeso

Reputation: 192417

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

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

Upvotes: 1

Related Questions