Попытка использовать Boost 1.69.0 из CLION во время работы Visual Studio, но выдает странные ошибки MINGW - PullRequest
0 голосов
/ 04 февраля 2019

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)

1 Ответ

0 голосов
/ 04 февраля 2019

Хорошо, многие ребята помогают мне это исправить.И это правда, но для тех, кто пытается скомпилировать для Visual Studio сразу с помощью CLion и cmake-js и Electron, решение было таково, что, поскольку 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()
...