Search code examples
c++ubuntuboostcmakeclion

Undefined reference error while building Boost with CMake and Clion on Ubuntu


(undefinierter Verweis is german and means undifined Reference)

Hi, i am using CLion with CMake 3.14, Ubuntu, BOoost 1.72.0 default compiler gcc/g++

I got this error (after deleting CMakeCache.txt):

I installed boost with

sudo apt-get install libboost-all-dev

AND/OR with

./bootstap.sh ./b2 install --prefix="/home/sebastian/boost_1_72_0"

this is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(Sceduling)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")


set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_NO_BOOST_CMAKE ON)

find_package(Boost COMPONENTS filesystem REQUIRED)

add_executable(Sceduling main.cpp account.cpp bank_t.cpp alternation.cpp transaction.c)
target_link_libraries(Sceduling PRIVATE Boost::filesystem)

this is the result:

====================[ Clean | Debug ]===========================================
/opt/clion-2019.1.4/bin/cmake/linux/bin/cmake --build /home/sebastian/Schreibtisch/git/ba-sebastian-dietl/Code/Bank_TM_Sceduling/cmake-build-debug --target clean -- -j 3
CMake Error: The current CMakeCache.txt directory /home/sebastian/Schreibtisch/CMakeCache.txt is different than the directory /home/sebastian/Schreibtisch/git/ba-sebastian-dietl/Code/Bank_TM_Sceduling/cmake-build-debug where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

Clean finished

====================[ Build | all | Debug ]=====================================
/opt/clion-2019.1.4/bin/cmake/linux/bin/cmake --build /home/sebastian/Schreibtisch/git/ba-sebastian-dietl/Code/Bank_TM_Sceduling/cmake-build-debug --target all -- -j 3
CMake Error: The current CMakeCache.txt directory /home/sebastian/Schreibtisch/CMakeCache.txt is different than the directory /home/sebastian/Schreibtisch/git/ba-sebastian-dietl/Code/Bank_TM_Sceduling/cmake-build-debug where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /opt/clion-2019.1.4/bin/cmake/linux/share/cmake-3.14/Modules/FindBoost.cmake:905 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  /opt/clion-2019.1.4/bin/cmake/linux/share/cmake-3.14/Modules/FindBoost.cmake:1027 (_Boost_COMPONENT_DEPENDENCIES)
  /opt/clion-2019.1.4/bin/cmake/linux/share/cmake-3.14/Modules/FindBoost.cmake:1709 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:15 (find_package)


-- Boost version: 1.72.0
-- Found the following Boost libraries:
--   filesystem
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sebastian/Schreibtisch/git/ba-sebastian-dietl/Code/Bank_TM_Sceduling/cmake-build-debug
Scanning dependencies of target Sceduling
[ 16%] Building CXX object CMakeFiles/Sceduling.dir/main.cpp.o
[ 33%] Building CXX object CMakeFiles/Sceduling.dir/bank_t.cpp.o
[ 50%] Building CXX object CMakeFiles/Sceduling.dir/account.cpp.o
[ 66%] Building CXX object CMakeFiles/Sceduling.dir/alternation.cpp.o
[ 83%] Building C object CMakeFiles/Sceduling.dir/transaction.c.o
[100%] Linking CXX executable Sceduling
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::context::fiber::~fiber()«:
main.cpp:(.text._ZN5boost7context5fiberD2Ev[_ZN5boost7context5fiberD5Ev]+0x5b): Warnung: undefinierter Verweis auf »ontop_fcontext«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::context::fiber::resume() &&«:
main.cpp:(.text._ZNO5boost7context5fiber6resumeEv[_ZNO5boost7context5fiber6resumeEv]+0x6e): Warnung: undefinierter Verweis auf »jump_fcontext«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::context::context(unsigned long, boost::fibers::type, boost::fibers::launch)«:
main.cpp:(.text._ZN5boost6fibers7contextC2EmNS0_4typeENS0_6launchE[_ZN5boost6fibers7contextC5EmNS0_4typeENS0_6launchE]+0x1a): Warnung: undefinierter Verweis auf »vtable for boost::fibers::context«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::fiber::fiber<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>, , void, void, void>(boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>&&)«:
main.cpp:(.text._ZN5boost6fibers5fiberC2INS_3_bi6bind_tIvPFvvENS3_5list0EEEJEvvvEEOT_DpT0_[_ZN5boost6fibers5fiberC5INS_3_bi6bind_tIvPFvvENS3_5list0EEEJEvvvEEOT_DpT0_]+0x21): Warnung: undefinierter Verweis auf »boost::context::stack_traits::default_size()«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::fiber::fiber<boost::context::basic_fixedsize_stack<boost::context::stack_traits>, boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>(boost::fibers::launch, std::allocator_arg_t, boost::context::basic_fixedsize_stack<boost::context::stack_traits>&&, boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>&&)«:
main.cpp:(.text._ZN5boost6fibers5fiberC2INS_7context21basic_fixedsize_stackINS3_12stack_traitsEEENS_3_bi6bind_tIvPFvvENS7_5list0EEEJEEENS0_6launchESt15allocator_arg_tOT_OT0_DpT1_[_ZN5boost6fibers5fiberC5INS_7context21basic_fixedsize_stackINS3_12stack_traitsEEENS_3_bi6bind_tIvPFvvENS7_5list0EEEJEEENS0_6launchESt15allocator_arg_tOT_OT0_DpT1_]+0x5f): Warnung: undefinierter Verweis auf »boost::fibers::fiber::start_()«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::worker_context<boost::context::basic_fixedsize_stack<boost::context::stack_traits> >(boost::fibers::launch, boost::context::preallocated const&, boost::context::basic_fixedsize_stack<boost::context::stack_traits>&&, boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>&&)«:
main.cpp:(.text._ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEEC2INS_7context21basic_fixedsize_stackINSA_12stack_traitsEEEEENS0_6launchERKNSA_12preallocatedEOT_OS7_[_ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEEC5INS_7context21basic_fixedsize_stackINSA_12stack_traitsEEEEENS0_6launchERKNSA_12preallocatedEOT_OS7_]+0x12f): Warnung: undefinierter Verweis auf »boost::fibers::context::~context()«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::run_(boost::context::fiber&&)«:
main.cpp:(.text._ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEE4run_EONS_7context5fiberE[_ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEE4run_EONS_7context5fiberE]+0x94): Warnung: undefinierter Verweis auf »boost::fibers::context::terminate()«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »void* boost::context::detail::create_fiber2<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::*(boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>*, std::_Placeholder<1>))(boost::context::fiber&&)> >, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::*(boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>*, std::_Placeholder<1>))(boost::context::fiber&&)> >(boost::context::preallocated, boost::context::basic_fixedsize_stack<boost::context::stack_traits>&&, std::_Bind<boost::context::fiber (boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::*(boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>*, std::_Placeholder<1>))(boost::context::fiber&&)>&&)«:
main.cpp:(.text._ZN5boost7context6detail13create_fiber2INS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEES7_SP_EEPvNS0_12preallocatedEOT0_OT1_[_ZN5boost7context6detail13create_fiber2INS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEES7_SP_EEPvNS0_12preallocatedEOT0_OT1_]+0xea): Warnung: undefinierter Verweis auf »make_fcontext«
main.cpp:(.text._ZN5boost7context6detail13create_fiber2INS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEES7_SP_EEPvNS0_12preallocatedEOT0_OT1_[_ZN5boost7context6detail13create_fiber2INS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEES7_SP_EEPvNS0_12preallocatedEOT0_OT1_]+0x127): Warnung: undefinierter Verweis auf »jump_fcontext«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »void boost::context::detail::fiber_entry<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::*(boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>*, std::_Placeholder<1>))(boost::context::fiber&&)> > >(boost::context::detail::transfer_t)«:
main.cpp:(.text._ZN5boost7context6detail11fiber_entryINS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE[_ZN5boost7context6detail11fiber_entryINS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE]+0x7c): Warnung: undefinierter Verweis auf »jump_fcontext«
main.cpp:(.text._ZN5boost7context6detail11fiber_entryINS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE[_ZN5boost7context6detail11fiber_entryINS1_12fiber_recordINS0_5fiberENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFMNS_6fibers14worker_contextINS_3_bi6bind_tIvPFvvENSB_5list0EEEJEEEFS4_OS4_EPSH_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE]+0xdd): Warnung: undefinierter Verweis auf »ontop_fcontext«
CMakeFiles/Sceduling.dir/main.cpp.o: In Funktion »boost::fibers::worker_context<boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>>::~worker_context()«:
main.cpp:(.text._ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEED2Ev[_ZN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEED5Ev]+0x22): Warnung: undefinierter Verweis auf »boost::fibers::context::~context()«
CMakeFiles/Sceduling.dir/main.cpp.o:(.data.rel.ro._ZTIN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEEE[_ZTIN5boost6fibers14worker_contextINS_3_bi6bind_tIvPFvvENS2_5list0EEEJEEE]+0x10): Warnung: undefinierter Verweis auf »typeinfo for boost::fibers::context«
collect2: error: ld returned 1 exit status
CMakeFiles/Sceduling.dir/build.make:144: recipe for target 'Sceduling' failed
make[2]: *** [Sceduling] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/Sceduling.dir/all' failed
make[1]: *** [CMakeFiles/Sceduling.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Update: Build worked, if i don't use fiber the programm finishes with Exit Code 0. If i use Fiber i get Process finished with exit code 135 (interrupted by signal 7: SIGEMT)

this is my Code:

#include <iostream>
#include <boost/fiber/all.hpp>                                                                      

using namespace std;
using namespace boost;

inline
void fn() {
    cout << "Hello World" << endl;
}

int main() {
    fibers::fiber f1(fn);
    f1.join();
    return 0;
}

Solution

  • If you can use the Ubuntu Boost package, install it with the following command:

    sudo apt-get install libboost-all-dev
    

    Then your CMakeLists.txt file should look like follows:

    set(CMAKE_CXX_STANDARD 11)
    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_NO_BOOST_CMAKE ON)
    
    find_package(Boost COMPONENTS fiber system filesystem REQUIRED)
    
    add_executable(Sceduling main.cpp account.cpp bank_t.cpp alternation.cpp transaction.c)
    target_link_libraries(Sceduling PRIVATE Boost::headers Boost::fiber Boost::system Boost::filesystem)
    

    Otherwise if you intend to build boost yourself and install it in a custom folder your CMakeLists.txt file should look like follows:

    set(CMAKE_CXX_STANDARD 11)
    set(Boost_ADDITIONAL_VERSIONS 1.72.0 1.72)
    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_NO_SYSTEM_PATHS ON)
    set(Boost_NO_BOOST_CMAKE ON)
    set(Boost_ROOT <mydir>)
    set(Boost_INCLUDEDIR <a_directory_with_include_files>)
    set(Boost_LIBRARYDIR <a_directory_with_library_files>)
    
    find_package(Boost 1.72.0 COMPONENTS fiber system filesystem REQUIRED)
    
    add_executable(Sceduling main.cpp account.cpp bank_t.cpp alternation.cpp transaction.c)
    target_link_libraries(Sceduling PRIVATE Boost::headers Boost::fiber Boost::system Boost::filesystem)
    

    Where 1.72.0 is the version of Boost you have previously built and installed to <mydir>. If the installation puts include files and libraries under seperate directories you need to reference them in the variables Boost_INCLUDEDIR and Boost_LIBRARYDIR.

    • Your CMake (3.14) is quite old and its FindBoost module does not now about the recent version of Boost (1.72.0). That's why you may need to set the Boost_ADDITIONAL_VERSIONS variable.

    • No need to check Boost_FOUND as the REQUIRED keyword makes CMake fail if Boost cannot be found.

    • Your target is called Sceduling not executable.

    • You need at least C++11 enabled for Boost::fiber to work.

    For further explanation of the settings please refere to the FindBoost CMake documentation.