You are not logged in.

#1 2016-01-24 17:38:05

apolih
Member
Registered: 2015-04-26
Posts: 3

[SOLVED]ld: cannot find -l{LIBRARY} in some contexts but can in others

I'll just ask my question first then provide details.
Are there any environment variables that affect the success of ld?
Perhaps some that may be (un)commonly set in Makefiles that I should be looking for?
Does anyone have advice for debugging ld problems?

I am trying to compile some bioinformatics tools: https://github.com/ncbi/sra-tools .
This project has a fairly complicated build process with a lot of different Makefiles for various tools.
The one giving me issues is called pacbio-load.

My compilation is failing:

[apoh@alkali pacbio-load]$ pwd
/home/apoh/repo/sra-tools/tools/pacbio-load

[apoh@alkali pacbio-load]$ make

make[1]: Entering directory '/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/obj/tools/pacbio-load'
gcc -static-libstdc++ -static-libgcc -o /home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/bin/pacbio-load.2.5.7 -DNDEBUG -m64 pl-context.o pl-tools.o pl-zmw.o pl-basecalls_cmn.o pl-sequence.o pl-consensus.o pl-passes.o pl-metrics.o pl-regions.o pl-progress.o pacbio-load.o -L/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/lib -L/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/ilib -L/usr/local/ngs/ngs-sdk/lib64 -L/home/apoh/ncbi-outdir/ncbi-vdb/linux/gcc/x86_64/rel/lib -L/home/apoh/ncbi-outdir/ncbi-vdb/linux/gcc/x86_64/rel/ilib -Wl,-Bstatic -lkapp -lkdf5 -lload -lhdf5 -lncbi-wvdb -Wl,-Bdynamic -ldl -lpthread -lxml2 -Wl,-Bdynamic -lm
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
/home/apoh/repo/sra-tools/tools/pacbio-load/Makefile:140: recipe for target '/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/bin/pacbio-load' failed
make[1]: *** [/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/bin/pacbio-load] Error 1
make[1]: Leaving directory '/home/apoh/ncbi-outdir/sra-tools/linux/gcc/x86_64/rel/obj/tools/pacbio-load'
Makefile:60: recipe for target 'std' failed
make: *** [std] Error 2

So I noticed in particular the line

/usr/bin/ld: cannot find -lhdf5

This is strange since I seem to hav e this library:

[apoh@alkali pacbio-load]$ ls -l /usr/lib/libhdf5.so
lrwxrwxrwx 1 root root 17 Oct 27 19:43 /usr/lib/libhdf5.so -> libhdf5.so.10.0.1

And this link is not dead

[apoh@alkali pacbio-load]$ ls /usr/lib/libhdf5.so.10.0.1
/usr/lib/libhdf5.so.10.0.1

And other times ld has no problem linking to this library:

ld --verbose -lhdf5 | curl -F c=@- https://ptpb.pw

https://ptpb.pw/DEi-

which in particular we have the lines at the end

attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libhdf5.so failed
attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libhdf5.a failed
attempt to open /usr/lib/libhdf5.so succeeded
-lhdf5 (/usr/lib/libhdf5.so)

which shows the library is found.

Thanks for the help.

Last edited by apolih (2016-01-25 16:30:04)

Offline

#2 2016-01-24 20:34:43

The Infinity
Member
Registered: 2014-07-05
Posts: 91
Website

Re: [SOLVED]ld: cannot find -l{LIBRARY} in some contexts but can in others

You're trying to link statically against the library. This might be the cause of the problem. You're also linking statically against the C++ standard library which is also a bad idea if you use exceptions across the libs.
You should also share your ./configure / cmake / qmake ... call to create the Makefile.

Offline

#3 2016-01-25 16:29:08

apolih
Member
Registered: 2015-04-26
Posts: 3

Re: [SOLVED]ld: cannot find -l{LIBRARY} in some contexts but can in others

Hi The Infinity, thanks very much for your reply.

I was not super familiar with gcc options and how to force to load a library as static or dynamic but after learning a bit more based on your comment I have found a solution. Details below in case it helps others. Indeed, the library was trying to be loaded as a static library from the gcc command

gcc ... -Bstatic ... -lhdf5

My fix was to figure out how this gcc command was being built, and why hdf5 is put in the static library section. Ultimately this starts with the configure script to generate the Makefile as you mentioned. The configure script calls a large perl script to generate the Makefile. Because there are so many shell scripts and included Makefiles involved in this process, I actually decided to work backwards and inject some echos into some of the make targets. There I found that the pacbio-load Makefile that was giving me problems had the lines.

PACBIO_LOAD_LIB = \
	-skapp \
	-skdf5 \
	-sload \
	-shdf5 \
	-sncbi-wvdb \
	-sm \

where a separate shell script interprets the leading "-s" to put the library in the static section. A comment at the top of that file mentions that "-l" can be used as an alternative where the script will then determine if a static or dynamic library already exists on the system and use the appropriate one. Now it compiles!

This all seems a bit pathological to me but I am fairly ignorant about the design of Makefiles for large projects.

Anyway, thanks again for the hints.

Offline

Board footer

Powered by FluxBB