尝试在Visual Studio工作时使用CLION的Boost 1.69.0,但给出了奇怪的MINGW错误

Trying to use Boost 1.69.0 from CLION while Visual Studio works, but giving weird MINGW errors

本文关键字:错误 MINGW Boost Studio Visual 工作 CLION      更新时间:2023-10-16

Visual Studio is aweomse.它可以工作,但我喜欢使用 CLION 并且没有调试功能,所以我尝试使用 MINGW,但我得到了这个奇怪的undefined reference错误。

我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)
project (fai C CXX)
#set(Boost_ARCHITECTURE "-x64")
set(Boost_DEBUG ON)
set(BOOST_NO_SYSTEM_PATHS ON)
set(BOOST_USE_MULTITHREADED  ON)
set(BOOST_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ALL_DYN_LINK OFF)
if (MSVC)
    set(BOOST_ROOT "C:/boost_1_69_0")
    set(Boost_INCLUDE_DIRS ${BOOST_ROOT})
    set(Boost_LIBRARY_DIRS ${BOOST_ROOT}/stage/lib/)
else()
    set(BOOST_ROOT "C:/boost_1_69_0")
    set(Boost_INCLUDE_DIRS ${BOOST_ROOT})
    set(Boost_LIBRARY_DIRS ${BOOST_ROOT}/stage/lib/)
    #set(BOOST_USE_WINAPI_VERSION 0x0601)
    #set(BOOST_ROOT "C:/boost_1_69_0")
    #set(BOOST_INCLUDEDIR ${BOOST_ROOT})
    #set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/)
    #set(BOOST_ROOT "C:/MinGW")
    #set(BOOST_INCLUDEDIR ${BOOST_ROOT}/include)
    #set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib/)
    #find_package(BOOST 1.69.0 COMPONENTS chrono filesystem system REQUIRED )
endif (MSVC)
include_directories(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
MESSAGE("Boost information:")
MESSAGE("  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
MESSAGE("  Boost_LIBRARIES: ${Boost_LIBRARIES}")
MESSAGE("  Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")

include_directories(${CMAKE_JS_INC})
#file(GLOB SOURCE_FILES "src/native/test/.cc" "src/native/pi-worker.cc" "src/native/arrayfire/pi-worker.cc" "src/native/arrayfire/test.cc")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${Boost_INCLUDE_DIRS} src/native/test/test1.cpp src/native/component/Index.cpp src/native/component/Index.h)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}  )
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/node_modules/node-addon-api")

if (CMAKE_JS_VERSION)
else()
    add_executable (test1 src/native/test/test1.cpp src/native/component/Index.cpp src/native/component/Index.h)
endif()

所以现在从这部分开始,它构建并与Visual Studio一起工作,但是鉴于我尝试使用CLION进行调试,我尝试使用MingW(除了我也尝试了CYGWIN,但得到了确切的错误!!!(。

所以这是错误:

====================[ Build | test1 | Debug ]===================================
"C:Program FilesJetBrainsCLion 2018.3.4bincmakewinbincmake.exe" --build C:Userspatrikx3Projectssygnusfinancial-ai-workspacefinancial-ai-electroncmake-build-debug --target test1 -- -j 4
Scanning dependencies of target test1
[ 66%] Building CXX object CMakeFiles/test1.dir/src/native/test/test1.cpp.obj
[ 66%] Building CXX object CMakeFiles/test1.dir/src/native/component/Index.cpp.obj
[100%] Linking CXX executable test1.exe
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(test1.cpp.obj): in function `boost::timer::cpu_timer::cpu_timer()':
C:/boost_1_69_0/boost/timer/timer.hpp:61: undefined reference to `boost::timer::cpu_timer::start()'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(test1.cpp.obj): in function `boost::timer::cpu_timer::format[abi:cxx11](short) const':
C:/boost_1_69_0/boost/timer/timer.hpp:69: undefined reference to `boost::timer::cpu_timer::elapsed() const'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/boost_1_69_0/boost/timer/timer.hpp:69: undefined reference to `boost::timer::format[abi:cxx11](boost::timer::cpu_times const&, short)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/boost_1_69_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/boost_1_69_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const&)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::is_directory(boost::filesystem::path const&)':
C:/boost_1_69_0/boost/filesystem/operations.hpp:453: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::create_directory(boost::filesystem::path const&)':
C:/boost_1_69_0/boost/filesystem/operations.hpp:574: undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::remove_all(boost::filesystem::path const&)':
C:/boost_1_69_0/boost/filesystem/operations.hpp:673: undefined reference to `boost::filesystem::detail::remove_all(boost::filesystem::path const&, boost::system::error_code*)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::detail::dir_itr_imp::~dir_itr_imp()':
C:/boost_1_69_0/boost/filesystem/operations.hpp:874: undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&)':
C:/boost_1_69_0/boost/filesystem/operations.hpp:905: undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFilestest1.dir/objects.a(Index.cpp.obj): in function `boost::filesystem::directory_iterator::increment()':
C:/boost_1_69_0/boost/filesystem/operations.hpp:941: undefined reference to `boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFilestest1.dirbuild.make:102: test1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:109: CMakeFiles/test1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:121: CMakeFiles/test1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:130: test1] Error 2

鉴于我同时使用Visual Studio和GCC,它有点不同,因为它使用cmake

add_executable (test1 src/native/test/test1.cpp src/native/component/Index.cpp src/native/component/Index.h)
    if (MSVC)
    else()
        target_link_libraries(test1 boost_filesystem boost_timer boost_chrono boost_system)
    endif (MSVC)

好的,很多人帮助我解决这个问题。这是真的,但是对于那些试图使用CLion,cmake-js和Electron立即为Visual Studio编译的人来说,解决方案是,因为Visual Studio自己发现,对于MinGW,您必须设置链接库(除非您在Windows或Linux中(:

#set(BOOST_ARCHITECTURE "-x64")
set(Boost_DEBUG ON)
#set(CMAKE_VERBOSE_MAKEFILE ON)
if (MSVC)
    set(BOOST_NO_SYSTEM_PATHS ON)
    set(BOOST_USE_MULTITHREADED  ON)
    set(BOOST_USE_STATIC_LIBS ON)
    set(BOOST_USE_STATIC_RUNTIME OFF)
    set(BOOST_ALL_DYN_LINK OFF)
    set(BOOST_ROOT "C:/boost_1_69_0")
    set(BOOST_INCLUDE_DIRS ${BOOST_ROOT})
    set(BOOST_LIBRARY_DIRS ${BOOST_ROOT}/stage/lib/)
else()
    #set(BOOST_ROOT "C:/boost_1_69_0")
    #set(BOOST_INCLUDE_DIRS ${BOOST_ROOT})
    #set(BOOST_LIBRARY_DIRS ${BOOST_ROOT}/stage/lib/)
    if (WIN32)
        set(BOOST_ROOT "C:/MinGW")
        set(BOOST_INCLUDE_DIRS ${BOOST_ROOT}/include)
        set(BOOST_LIBRARY_DIRS ${BOOST_ROOT}/lib/)
    endif (WIN32)
    find_package(Boost COMPONENTS timer filesystem system REQUIRED )
endif (MSVC)
include_directories(${BOOST_INCLUDE_DIRS})
LINK_DIRECTORIES(${BOOST_LIBRARY_DIRS})
if (CMAKE_JS_VERSION)
else()
    add_executable (test1 src/native/test/test1.cpp src/native/component/Index.cpp src/native/component/Index.h)
    if (NOT MSVC)
        target_link_libraries(test1 boost_filesystem boost_timer boost_chrono boost_system)
    endif (NOT MSVC)
endif()