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

find_package cannot find Boost #5687

Closed
Mohammadabd opened this issue Mar 16, 2020 · 2 comments · Fixed by #6083
Closed

find_package cannot find Boost #5687

Mohammadabd opened this issue Mar 16, 2020 · 2 comments · Fixed by #6083

Comments

@Mohammadabd
Copy link

I have built osrm-backend successfully on my mac machine, but when CMake example I get multiple warning related to boost such as

Target "osrm-example" links to target "Boost::regex" but the target was not found.  Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

and then when running build it throws error and fails

ld: library not found for -lBoost::regex

How to get around this issue? I have boost already installed. Thanks

ls /usr/local/Cellar/boost/
1.72.0
@Mohammadabd
Copy link
Author

FIX:
in ./example/CMakeLists.txt add
find_package(Boost 1.52.0 COMPONENTS filesystem system thread iostreams chrono date_time regex REQUIRED)

@mjjbell
Copy link
Member

mjjbell commented Jul 8, 2021

This is happening because FindBoost changed (I think in cmake v3.11) to use Imported Targets for library component variables, rather than file paths to the Boost libraries.

cmake uses these targets when linking (e.g. target_link_library) and knows how to correctly substitute the values. However, the OSRM pkg-config file that we generate doesn't do this, and ends up writing the actual target symbols, hence the errors trying to link Boost::<component>

The example works when OSRM is built with older versions of cmake (CI is using 3.7.2) as you get the old behaviour of writing file paths to libosrm.pc.

To fix this for newer cmake versions, I think we need to add a file(GENERATE... step to the pkg-config creation, which has the information needed to make the imported target substitutions, as suggested here: https://cmake.org/pipermail/cmake/2018-December/068812.html

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

Successfully merging a pull request may close this issue.

2 participants