Question

I have built and installed a shared library to do some profiling of my projects via code instrumentation, specifically with the -finstrument-functions switch of gcc.

It is possible to turn the instrumentation on and off with the compiler switch, and hence I'd like to be able to turn the dependency to the profiling library on and off just by reconfiguring.

I can pass -finstrument-functions to gcc via configure's CFLAGS, but when I try to pass -lmylib via LDFLAGS configure fails with

configure:2796: checking whether we are cross compiling
configure:2804: gcc -o conftest -g -Wall -Wextra -Werror  -lmylib conftest.c  >&5
configure:2808: $? = 0
configure:2815: ./conftest 
./conftest: error while loading shared libraries: libmylib.so.0: cannot open shared object file: No such file or directory

The file exists, I have double checked and compiling and linking a dummy example works as expected.

Interestingly, when I pass the full path to the shared library instead of -lmylib, the error persists, but when I pass the full path to the corresponding static library, configure runs smoothly, and everything is built as expected.

My question in a nutshell: Is there a possibility to pass optional shared libraries to autotools-generated configure scripts, without changing configure.ac?

Thanks, Andy

Was it helpful?

Solution 2

fixed by running sudo ldconfig

I'll leave this here in case someone else has the same problem.

OTHER TIPS

It looks like your library is not in the compiler's default library search path. You may also pass library search path through LDFLAGS with the -L switch:

CFLAGS=-finstrument-functions LDFLAGS="-lmylib -L/path/to/mylib" ./configure ....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top