简体   繁体   中英

Find the “name” of a library (-L -l switches)

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?

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.

通常,如果使用第二种形式的LDLIBS声明,则应在-llibjpeg中删除字母lib以获得-ljpeg。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM