I'm trying to build a minimal Cobalt library sample. I'm getting link errors:
Build and installed Boost with:
./bootstrap.sh --prefix=$HOME/.local
./b2 install
Sample:
#include
#include <iostream>
boost::cobalt::main co_main(int, char *[])
{
std::cout << "Hello world\n";
co_return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(coro_study)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(Boost_VERBOSE 1)
set(Boost_DEBUG 1)
find_package(Boost REQUIRED COMPONENTS system)
add_executable(sample sample.cpp)
target_include_directories(sample4 PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(sample4 PRIVATE ${Boost_LIBRARIES})
cmake output:
dev ~/Projects/coroutines/x64-linux-debug $ cmake ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost 1.84.0 at /home/dev/.local/lib/cmake/Boost-1.84.0
-- Requested configuration: QUIET REQUIRED COMPONENTS system
-- BoostConfig: find_package(boost_headers 1.84.0 EXACT CONFIG
REQUIRED QUIET HINTS /home/dev/.local/lib/cmake)
-- Found boost_headers 1.84.0 at /home/dev/.local/lib/cmake/boost_headers-1.84.0
-- BoostConfig: find_package(boost_system 1.84.0 EXACT CONFIG REQUIRED
QUIET HINTS /home/dev/.local/lib/cmake)
-- Found boost_system 1.84.0 at /home/dev/.local/lib/cmake/boost_system-1.84.0
-- Boost toolset is gcc11 (GNU 11.4.0)
-- Scanning /home/dev/.local/lib/cmake/boost_system-1.84.0/libboost_system-variant*.cmake
-- Including /home/dev/.local/lib/cmake/boost_system-1.84.0/libboost_system-variant-shared.cmake
-- [x] libboost_system.so.1.84.0
-- Including /home/dev/.local/lib/cmake/boost_system-1.84.0/libboost_system-variant-static.cmake
-- [ ] libboost_system.a
-- Adding boost_system dependencies: headers
-- Found Boost:
/home/dev/.local/lib/cmake/Boost-1.84.0/BoostConfig.cmake (found
version "1.84.0") found components: system
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/dev/Projects/coroutines/x64-linux-debug
make output:
dev ~/Projects/coroutines/x64-linux-debug $ make
/usr/bin/cmake -S/home/dev/Projects/coroutines
-B/home/dev/Projects/coroutines/x64-linux-debug --check-build-system
CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start
/home/dev/Projects/coroutines/x64-linux-debug/CMakeFiles
/home/dev/Projects/coroutines/x64-linux-debug//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dev/Projects/coroutines/x64-linux-debug'
make -f CMakeFiles/sample4.dir/build.make CMakeFiles/sample4.dir/depend
make[2]: Entering directory '/home/dev/Projects/coroutines/x64-linux-debug'
cd /home/dev/Projects/coroutines/x64-linux-debug && /usr/bin/cmake -E
cmake_depends "Unix Makefiles" /home/dev/Projects/coroutines
/home/dev/Projects/coroutines
/home/dev/Projects/coroutines/x64-linux-debug
/home/dev/Projects/coroutines/x64-linux-debug
/home/dev/Projects/coroutines/x64-linux-debug/CMakeFiles/sample4.dir/DependInfo.cmake
--color=
make[2]: Leaving directory '/home/dev/Projects/coroutines/x64-linux-debug'
make -f CMakeFiles/sample4.dir/build.make CMakeFiles/sample4.dir/build
make[2]: Entering directory '/home/dev/Projects/coroutines/x64-linux-debug'
[ 50%] Building CXX object CMakeFiles/sample4.dir/sample4.cpp.o
/usr/bin/c++ -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_NO_LIB -isystem
/home/dev/.local/include -std=gnu++20 -MD -MT
CMakeFiles/sample4.dir/sample4.cpp.o -MF
CMakeFiles/sample4.dir/sample4.cpp.o.d -o
CMakeFiles/sample4.dir/sample4.cpp.o -c
/home/dev/Projects/coroutines/sample4.cpp
[100%] Linking CXX executable sample4
/usr/bin/cmake -E cmake_link_script CMakeFiles/sample4.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/sample4.dir/sample4.cpp.o -o sample4
/home/dev/.local/lib/libboost_system.so.1.84.0
/usr/bin/ld: CMakeFiles/sample4.dir/sample4.cpp.o: in function
`co_main(co_main(int, char**)::_Z7co_mainiPPc.Frame*) [clone .actor]':
sample4.cpp:(.text+0x2a9): undefined reference to
`boost::cobalt::detail::main_promise::final_suspend()'
/usr/bin/ld: CMakeFiles/sample4.dir/sample4.cpp.o: in function
`main::reset_res::operator()(std::pmr::memory_resource*)':
sample4.cpp:(.text._ZZ4mainEN9reset_resclEPNSt3pmr15memory_resourceE[_ZZ4mainEN9reset_resclEPNSt3pmr15memory_resourceE]+0x1c):
undefined reference to
`boost::cobalt::this_thread::set_default_resource(std::pmr::memory_resource*)'
/usr/bin/ld: CMakeFiles/sample4.dir/sample4.cpp.o: in function `main':
sample4.cpp:(.text.main[main]+0x5b): undefined reference to
`boost::cobalt::this_thread::set_default_resource(std::pmr::memory_resource*)'
/usr/bin/ld: sample4.cpp:(.text.main[main]+0xc2): undefined reference
to `boost::cobalt::detail::main_promise::run_main(boost::cobalt::main)'
/usr/bin/ld: CMakeFiles/sample4.dir/sample4.cpp.o: in function `bool
boost::cobalt::detail::promise_receiver<void>::awaitable::await_suspendboost::cobalt::detail::fork::promise_type(std::__n4861::coroutine_handleboost::cobalt::detail::fork::promise_type)':
sample4.cpp:(.text._ZN5boost6cobalt6detail16promise_receiverIvE9awaitable13await_suspendINS1_4fork12promise_typeEEEbNSt7__n486116coroutine_handleIT_EE[_ZN5boost6cobalt6detail16promise_receiverIvE9awaitable13await_suspendINS1_4fork12promise_typeEEEbNSt7__n486116coroutine_handleIT_EE]+0x7f):
undefined reference to `boost::cobalt::detail::already_awaited()'
/usr/bin/ld: CMakeFiles/sample4.dir/sample4.cpp.o: in function
`boost::cobalt::detail::promise_receiver<void>::awaitable::interrupt_await()
&':
sample4.cpp:(.text._ZNR5boost6cobalt6detail16promise_receiverIvE9awaitable15interrupt_awaitEv[_ZNR5boost6cobalt6detail16promise_receiverIvE9awaitable15interrupt_awaitEv]+0x33):
undefined reference to `boost::cobalt::detail::detached_exception()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/sample4.dir/build.make:101: sample4] Error 1
make[2]: Leaving directory '/home/dev/Projects/coroutines/x64-linux-debug'
make[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/sample4.dir/all] Error 2
make[1]: Leaving directory '/home/dev/Projects/coroutines/x64-linux-debug'
make: *** [Makefile:94: all] Error 2