boostorg / boostorg/boost_install

Are CMake files supposed to bring in dependencies?

Open
#27 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
11
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Consider this `CMakeLists.txt` file:
```
project(Boost CXX)
cmake_minimum_required(VERSION 3.0)

FIND_PACKAGE(Boost COMPONENTS thread REQUIRED)
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})

ADD_EXECUTABLE(test test.cpp)
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})
```
with this `test.cpp` file:
```
#include

int main() {
boost::condition_variable cv;
boost::mutex mutex;
boost::unique_lock lock(mutex);
cv.wait_for(lock, boost::chrono::seconds(1));
return 0;
}
```

When I try to compile with `cmake .` and `make`, the compilation fails with
```
[100%] Linking CXX executable test
/usr/bin/ld: CMakeFiles/test.dir/test.cpp.o: in function `boost::cv_status boost::condition_variable::wait_for >(boost::unique_lock&, boost::chrono::duration > const&)':
test.cpp:(.text._ZN5boost18condition_variable8wait_forIlNS_5ratioILl1ELl1EEEEENS_9cv_statusERNS_11unique_lockINS_5mutexEEERKNS_6chrono8durationIT_T0_EE[_ZN5boost18condition_variable8wait_forIlNS_5ratioILl1ELl1EEEEENS_9cv_statusERNS_11unique_lockINS_5mutexEEERKNS_6chrono8durationIT_T0_EE]+0x15): undefined reference to `boost::chrono::steady_clock::now()'
collect2: error: ld returned 1 exit status
```
Clearly `boost::condition_variable::wait_from` requires `boost::chrono::steady_clock::now`, but the latter is not automatically brought in as a dependency by CMake scripts. Should I expect CMake to automatically resolve dependencies towards other Boost libraries (i.e., this is a bug), or am I supposed to explicitly specify `chrono` in the `CMakeLists.txt` file?

Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.