LIBRARY_PATH handling differences with GCC(?)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

LIBRARY_PATH handling differences with GCC(?)

Tom Stellard via cfe-dev
Hi,

I ran into an issue linking a library with a specific libpng today.

The cmake build system found the desired library and set PNG_LIBRARIES="/opt/local/lib/libpng.so;/opt/local/lib/libz.so" . However, my build script also sets LIBRARY_PATH=/opt/local/lib so that I don't have to add -L/opt/local/lib to each and every linker call.

Because of this, cmake rewrites the PNG_LIBRARIES value to "-lpng -lz" when I use it in a link command.

That works fine with GCC but for some reason not with clang (4.0.1, installed via the Ubuntu .deb from llvm.org). With clang I get errors about missing symbols, which indicate that the system libpng is being pulled in.

I did  a very simple test comparing

%> env LIBRARY_PATH=/opt/local/lib g++ -v test.cpp -lpng
%> env LIBRARY_PATH=/opt/local/lib clang++ -v test.cpp -lpng

With g++ (7.1.0) the resulting a.out is linked to /opt/local/lib/libpng16.so while with clang++ it links to Ubuntu's libpng12.so . Comparing the actual link commands I notice that g++ invokes collect2 with -L/opt/local/lib BEFORE the first -lfoo library spec, while clang++ invokes /usr/bin/ld with -L/opt/local/lib set AFTER the user-specified -lfoo library specs.

Is there a reason for that, or is this a bug?

Thanks,
René
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...