views:

36

answers:

3

Being fairly new to C++ I have a question bascially concerning the g++ compiler and especially the inclusion of libraries. Consider the following makefile:

CPPFLAGS= -I libraries/boost_1_43_0-bin/include/ -I libraries/jpeg-8b-bin/include/
LDLIBS= libraries/jpeg-8b-bin/lib/libjpeg.a
# LDLIBS= -L libraries/jpeg-8b-bin/lib -llibjpeg

all: main

main: main.o
    c++ -o main main.o $(LDLIBS)

main.o: main.cpp
    c++ $(CPPFLAGS) -c main.cpp

clean:
    rm -rf *.o main

As you can see I declared the LDLIBS variable twice. My code is compiling and working if I use the makefile above. But if I deactivate the first LDLIBS entry and active the second one I get ld: library not found for -llibjpeg. I assume my libjpeg.a is just not called libjpeg but bears some different name.

Is there a way to find out the name of a given "libraryfile" libsomething.a or libsomething.dyn?


Ok, thanks for all your answers, it is working now. One little question remains: Is it a convention to simply leave out "lib" or is there a standardized way to find out the name?

+6  A: 

You don't need the lib part if you use the -l switch.

LDLIBS=-Llibraries/jpeg-8b-bin/lib -ljpeg
#                                    ^^^^

Whenever you write -lxxx, the linker will look for a library with filename libxxx.<ext> in all supplied library paths. This is the standard convention of ld, and should be true for most UNIX-based linkers.

KennyTM
+3  A: 

Typically if you use your second form of LDLIBS declaration you should drop the letters lib in -llibjpeg to get -ljpeg.

High Performance Mark
+3  A: 

No space between -I or -L and the path that follows, and -lxxx implies lib, so

-Llibraries/jpeg-8b-bin/lib -ljpeg

should do the trick.

xcramps