Reputation: 1798
I have a project which uses libibverbs. I have to compile this project on a server to run it there. The server has libibverbs installed system-wide, but unfortunately it doesn't support a feature which I need.
I decided to compile and use my own version of libibverbs, which has the corresponding feature. So I compiled the library, installed it to my home directory, and updated following environment variables: PATH, LD_LIBRARY_PATH, C_INCLUDE_PATH, LIBRARY_PATH, CPLUS_INCLUDE_PATH
Now I have to compile my project. First I call configure and it fails with following error message:
conftest.c:(.text.startup+0x7): undefined reference to `ibv_open_xrc_domain'
This is the symbol, which is missing in the system-wide version, but is present in the version I installed. First entry in LIBRARY_PATH is the path to the new libibversion, so I expected it is going to be used first, but it seems that the old version is used anyway.
Compilation command which ./configure uses, contains flag -L/libibverbs/1.1.4/lib, which points to the directory with the new library version. This flag goes just after -L/usr/lib/../lib64 which point to the directory, with system-wide libibverbs
If I put -L with new version in the end of command, the conftest compiles successfully.
To be clear following fails: https://gist.github.com/planetA/a421669269b14e69026c53f56fa45b2b
And following works: https://gist.github.com/planetA/3b0e22bf6aca3a1c67f30bfa3666d9a8
Could you help me to enforce picking the new version of the library in a way that configure catches it?
Upvotes: 1
Views: 508
Reputation: 61590
LD_LIBRARY_PATH
specifies directories to be searched, before the
defaults, for a library that is to be loaded in a process at runtime.
It does not affect the directories that are searched for a library
in order to link it at buildtime.
The linker searches for libraries in the directories that are specified
with the -L
dir option in its commandline, before it searches its
default directories. Your configure
script tests whether it can find a libibverbs
library in the linker's search directories that defines the function
ibv_open_xrc_domain
, and fails because it cannot. The value of LD_LIBRARY_PATH
does
not matter to this test.
For GNU make
, the -L
-options it should pass to the linker
are conventionally specified in the environment variable LDFLAGS
. GNU autoconf
- which
generates your configure
script - follows this convention. autoconf
generates
the configure
script from the project's configure.ac
file.
So, if your want your modified package to generate a generate a configure
script such that running ./configure
will in turn generate makefiles
in which -L
/my/library/version/is/here is passed to the linker then
you need to modify the project's configure.ac
like:
LDFLAGS="$LDFLAGS -L/my/library/version/is/here"
and you need to do this in the configure.ac
before it runs the test for
the libibverbs
library. After making this change you will need to reconfigure
the package by running autoreconf
in the project directrory, to regenerate
the configure
script.
If you don't want to change the configure.ac
like this then you can achieve the same
effect by:
./configure LDFLAGS="$LDFLAGS -L/my/library/version/is/here"
or:
export LDFLAGS="$LDFLAGS -L/my/library/version/is/here"
... # in same shell or a subshell
./configure
Then until the next time you run the configure
script the project's makefiles
will pass -L/my/library/version/is/here
to the linker. But the next time
you run ./configure
you must remember to set LDFLAGS
in the same way, or
the regenerated makefiles will revert to the default behaviour.
Upvotes: 1