Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installed libraries instead of newly built ones #322

Open
jmirabel opened this issue Jan 31, 2020 · 7 comments
Open

Installed libraries instead of newly built ones #322

jmirabel opened this issue Jan 31, 2020 · 7 comments

Comments

@jmirabel
Copy link
Collaborator

On 18.04, for a package with library and unit tests on this library, the unit test will find first the installed version of the library, rather than the one in the build folder. On 16.04, the behavior was different.

I couldn't find anything relevant with a websearch (my keywords may have been wrong). It may be related to this module. Two questions:

  • Anybody knows why ?
  • Anybody encountered this issue ?
@jcarpent
Copy link
Contributor

I think we should export the env viriable for the test containing first the compilations paths.

@jmirabel
Copy link
Collaborator Author

I think I understood the change of behavior. It is because on 16.04, CMake used to set rpath to the correct build folder. On 18.04, it sets runpath.
The order into which shared libs are looked for is: rpath, LB_LIBRARY_PATH and runpath.

@jmirabel
Copy link
Collaborator Author

The issue actually comes from the linker, i.e. ld on linux. In the past, runpath did not exist. When it both became available, runpath became the default. Thus the change of behavior.

Add option -Wl,--disable-new-dtags to CMAKE_EXE_LINKER_FLAG to tell ld to set rpath instead of runpath.

@jmirabel
Copy link
Collaborator Author

Last thought on this.

Setting the environment variable from CMake would work when CMake launch the unit tests. It wouldn't work when the unit test are run manually.

@florent-lamiraux
Copy link
Contributor

The order into which shared libs are looked for is: rpath, LB_LIBRARY_PATH and runpath.

Providing

SET_TARGET_PROPERTIES(${NAME} PROPERTIES BUILD_RPATH
  ${PROJECT_BINARY_DIR}/lib)

to my test, I get
/usr/lib/ccache/g++ -pedantic -Wno-long-long -Wall -Wextra -Wcast-align -Wcast-qual -Wformat -Wwrite-strings -Wconversion -rdynamic CMakeFiles/signal-ptr.dir/signal-ptr.cpp.o -o signal-ptr -Wl,-rpath,/home/florent/devel/pyrene/src/dynamic-graph/build-rel/lib ../lib/libdynamic-graph.so ...
So, option -rpath is present, but the test links with the installed version of the library libdynamic-graph.so.
This seems to refute the above assertion.

@florent-lamiraux
Copy link
Contributor

Add option -Wl,--disable-new-dtags to CMAKE_EXE_LINKER_FLAG to tell ld to set rpath instead of runpath.

This works for me. Should I make a pull request in this project ?

@jmirabel
Copy link
Collaborator Author

jmirabel commented Feb 5, 2020

This flag should be added only when supported by the linker. I don't know how to get this information...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants