Неопределенная ошибка ссылки при сборке Boost с CMake и Clion в Ubuntu - PullRequest
0 голосов
/ 04 марта 2020

(undefinierter Verweis - немецкий язык и означает неопределенную ссылку)

Привет, я использую CLion с CMake 3.14, Ubuntu, BOoost 1.72.0 компилятор по умолчанию gcc / g ++

Я получил эту ошибку (после удаления CMakeCache.txt):

Я установил boost с

sudo apt-get install libboost-all-dev

И / ИЛИ с

./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. Если я использую Fiber, процесс завершается с кодом выхода 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;
}

1 Ответ

0 голосов
/ 04 марта 2020

Если вы можете использовать пакет 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 - версия Boost, которую вы ранее создали, и установлен на <mydir>. Если в процессе установки подключаемые файлы и библиотеки размещаются в отдельных каталогах, вам нужно ссылаться на них в переменных Boost_INCLUDEDIR и Boost_LIBRARYDIR.

  • Ваш CMake (3.14) довольно старый и его модуль FindBoost теперь не относится к последней версии Boost (1.72.0). Вот почему вам может потребоваться установить переменную Boost_ADDITIONAL_VERSIONS.

  • Нет необходимости проверять Boost_FOUND, поскольку ключевое слово REQUIRED приводит к сбою CMake, если не удается найти Boost .

  • Ваша цель называется Sceduling, а не executable.

  • Вам необходим как минимум C ++ 11 для Boost::fiber на работу.

Для более подробного объяснения настроек, пожалуйста, обратитесь к FindBoost CMake документации.

...