簡體   English   中英

在 Ubuntu 上使用 CMake 和 Clion 構建 Boost 時出現未定義的參考錯誤

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

( undefinierter Verweis 是德語,意思是未定義的參考)

嗨,我正在使用 CLion 和 CMake 3.14、Ubuntu、BOoost 1.72.0 默認編譯器 gcc/g++

我收到此錯誤(刪除 CMakeCache.txt 后):

我安裝了 boost

須藤 apt-get 安裝 libboost-all-dev

AND/OR 與

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

這是我的 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)

這是結果:

====================[ 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

更新:構建有效,如果我不使用光纖,程序以退出代碼 0 結束。如果我使用光纖,我會以退出代碼 135 完成進程(被信號 7:SIGEMT 中斷)

這是我的代碼:

#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;
}

如果您可以使用 Ubuntu Boost軟件包,請使用以下命令安裝它:

sudo apt-get install libboost-all-dev

然后您的CMakeLists.txt文件應如下所示:

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)

否則,如果您打算自己構建 boost 並將其安裝在自定義文件夾中,您的CMakeLists.txt文件應如下所示:

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)

其中 1.72.0 是您之前構建並安裝到<mydir>Boost版本。 如果安裝將包含文件和庫放在單獨的目錄下,您需要在變量Boost_INCLUDEDIRBoost_LIBRARYDIR引用它們。

  • 你的CMake (3.14) 已經很老了,它的FindBoost模塊現在沒有關於Boost (1.72.0) 的最新版本。 這就是您可能需要設置Boost_ADDITIONAL_VERSIONS變量的原因。

  • 無需檢查Boost_FOUND因為如果找不到BoostREQUIRED關鍵字會使CMake失敗。

  • 您的目標稱為Sceduling not executable

  • 您至少需要啟用 C++11 才能讓Boost::fiber工作。

有關設置的進一步說明,請參閱FindBoost CMake 文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM