gpt4 book ai didi

c++ - 尝试在 Visual Studio 工作时使用 CLION 的 Boost 1.69.0,但出现奇怪的 MINGW 错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:30 25 4
gpt4 key购买 nike

Visual Studio 很棒。它有效,但我喜欢使用 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 Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\patrikx3\Projects\sygnus\financial-ai-workspace\financial-ai-electron\cmake-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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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: CMakeFiles\test1.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]: *** [CMakeFiles\test1.dir\build.make:102: test1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:109: CMakeFiles/test1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2: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()

关于c++ - 尝试在 Visual Studio 工作时使用 CLION 的 Boost 1.69.0,但出现奇怪的 MINGW 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54517701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com