I'm wondering what is wrong with my configuration that prevents it from running the Boost test.
I have this make file:
cmake_minimum_required(VERSION 3.10)
project(Fubi)
set(BOOST_ROOT "C:/local/boost_1_73_0")
set(Boost_INCLUDE_DIRS "C:/local/boost_1_73_0")
set(Boost_LIBRARY_DIRS "C:/local/boost_1_73_0/lib64-msvc-14.2")
set(Boost_USE_STATIC_LIBS ON)
message(STATUS "BOOST_ROOT: ${BOOST_ROOT}")
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
find_package(Boost REQUIRED)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
set(SOURCES DbgHelpDll.cpp Fubi.cpp SysExports.cpp fubimain.cpp stdafx.cpp)
add_executable(Fubi ${SOURCES})
target_link_libraries(Fubi PRIVATE DbgHelp)
set_property(TARGET Fubi PROPERTY ENTRY_POINT "fubimain.cpp")
set(CMAKE_GENERATOR_PLATFORM x86)
set(CMAKE_SYSTEM_VERSION 6.0)
set(TEST_SOURCES TestSignatureParser.cpp)
#add_definitions(-DBOOST_TEST_DYN_LINK)
add_definitions(-DBOOST_TEST_STATIC_LINK)
add_executable(tests ${TEST_SOURCES})
target_link_libraries(tests ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
message(STATUS "Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
Then trying to build the project with CLion:
====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build C:\Users\cyberquarks\ClionProjects\fubi\cmake-build-debug --target all --
[ 75%] Built target Fubi
Scanning dependencies of target tests
[ 87%] Building CXX object CMakeFiles/tests.dir/TestSignatureParser.cpp.obj
TestSignatureParser.cpp
[100%] Linking CXX executable tests.exe
LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx86\x86\link.exe /nologo #CMakeFiles\tests.dir\objects1.rsp /out:tests.exe /implib:tests.lib /pdb:C:\Users\cyberquarks\ClionProjects\fubi\cmake-build-debug\tests.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console -LIBPATH:C:\local\boost_1_73_0\stage\lib C:\local\boost_1_73_0\stage\lib\libboost_unit_test_framework-vc142-mt-gd-x32-1_73.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\tests.dir/intermediate.manifest CMakeFiles\tests.dir/manifest.res" failed (exit code 1120) with the following output:
libboost_unit_test_framework-vc142-mt-gd-x32-1_73.lib(unit_test_main.obj) : error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite##YAPAVtest_suite#unit_test#boost##HQAPAD#Z) referenced in function __catch$?unit_test_main#unit_test#boost##YAHP6APAVtest_suite#12#HQAPAD#ZH0#Z$4
tests.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
And here's the CMake log when the project was imported with the CLion IDEA (also during reloading):
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" C:\Users\cyberquarks\ClionProjects\fubi
-- BOOST_ROOT: C:/local/boost_1_73_0
-- Boost_INCLUDE_DIRS: C:/local/boost_1_73_0
-- Boost_LIBRARY_DIRS: C:/local/boost_1_73_0/lib64-msvc-14.2
-- Found Boost: C:/local/boost_1_73_0 (found version "1.73.0")
CMake Warning at C:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1144 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
C:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1266 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1904 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:21 (find_package)
-- Found Boost: C:/local/boost_1_73_0 (found version "1.73.0") found components: unit_test_framework
-- Compiler version: 19.29.30147.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cyberquarks/ClionProjects/fubi/cmake-build-debug
[Finished]
Here's the test source:
/**
* #file TestSignatureParser.cpp
* #brief
*
* #author
* #date 2022-12-20
*/
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
//#include "SysExports.h"
// Create a test suite
BOOST_AUTO_TEST_SUITE(SignatureParserTestSuite)
// Define a test case for parsing a valid function signature
BOOST_AUTO_TEST_CASE(ParseValidSignature) {
}
// Define a test case for parsing an invalid function signature
BOOST_AUTO_TEST_CASE(ParseInvalidSignature) {
}
// End the test suite
BOOST_AUTO_TEST_SUITE_END()
You've specified BOOST_TEST_NO_MAIN and then not implemented your own main, use BOOST_TEST_MODULE instead.
Related
So, I have no code, just empty files and a CMake, but I keep getting that Linker Error. Can someone please explain in a lot of detail what my problem is? Some info I have is that I am supposed to be using Visual Studio 2015 as my compiler and stuff, which I think I already have set up.
The Error:
[100%] Linking CXX executable Debug\CinderGame\CinderGame.exe
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.2.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
LINK Pass 1: command "C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo #CMakeFiles\CinderGame.dir\objects1.rsp /out:Debug\CinderGame\CinderGame.exe /implib:CinderGame.lib /pdb:C:\Users\cesar\Documents\GitHub\final-project-cesarmonsalud\cmake-build-debug\Debug\CinderGame\CinderGame.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:windows /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCPMT -LIBPATH:C:\Users\cesar\Desktop\cinder_0.9.2_vc2015\lib\msw\x86 C:\Users\cesar\Desktop\cinder_0.9.2_vc2015\lib\msw\x86\Debug\v140\cinder.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\CinderGame.dir/intermediate.manifest CMakeFiles\CinderGame.dir/manifest.res" failed (exit code 1120) with the following output:
LIBCMTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
Debug\CinderGame\CinderGame.exe : fatal error LNK1120: 1 unresolved externals
The Code:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
project(Connect4)
# This tells the compiler to not aggressively optimize and
# to include debugging information so that the debugger
# can properly read what's going on.
set(CMAKE_BUILD_TYPE Debug)
# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
# Let's nicely support folders in IDE's
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Warning flags
if(MSVC)
# warning level 3 and all warnings as errors
add_compile_options(/W3)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wpedantic -Werror)
endif()
# FetchContent added in CMake 3.11, downloads during the configure step
include(FetchContent)
# FetchContent_MakeAvailable was not added until CMake 3.14
if(${CMAKE_VERSION} VERSION_LESS 3.14)
include(cmake/add_FetchContent_MakeAvailable.cmake)
endif()
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG devel
)
# Adds Catch2 testing library
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_library(catch2 INTERFACE )
target_include_directories(catch2 INTERFACE ${catch2_SOURCE_DIR}/single_include)
endif()
get_filename_component(CINDER_PATH "C:/Users/cesar/Desktop/cinder_0.9.2_vc2015" ABSOLUTE)
get_filename_component(APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/" ABSOLUTE)
include("${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake")
list(APPEND CORE_SOURCE_FILES
)
list(APPEND SOURCE_FILES ${CORE_SOURCE_FILES}
include/core/Connect4.h
include/visualizer/FinalProjectApp.h
src/core/Connect4.cpp
src/visualizer/FinalProjectApp.cpp
)
list(APPEND TEST_FILES tests/Connect4Tests.cpp)
ci_make_app(
APP_NAME CinderGame
CINDER_PATH ${CINDER_PATH}
SOURCES apps/cinder_game.cpp ${SOURCE_FILES}
INCLUDES include
)
ci_make_app(
APP_NAME ConsoleGame
CINDER_PATH ${CINDER_PATH}
SOURCES apps/main_console_game.cpp ${SOURCE_FILES}
INCLUDES include
)
ci_make_app(
APP_NAME GameTest
CINDER_PATH ${CINDER_PATH}
SOURCES tests/Connect4Tests.cpp ${SOURCE_FILES} ${TEST_FILES}
INCLUDES include
LIBRARIES catch2
)
if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()
The culprit is probably:
if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()
This tells the linker to build for a console subsystem, which does not have an implicit WinMain function: you'd have to write one yourself if you need a console build.
If you don't need a console build, you can change it to /SUBSYSTEM:WINDOWS and a WinMain will be supplied by MFC.
I am trying to build my project on Windows. On Linux it works perfectly fine.
Here is my main CMakeLists.txt file:
cmake_minimum_required(VERSION 3.16)
project(Vibranium_Core)
set(CMAKE_CXX_STANDARD 17)
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
set(FLATBUFFERS_LOCATION "E:/vcpkg/packages/flatbuffers_x86-windows")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-list --count HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git --no-pager log -1 --format=%ai
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_RELEASED_ON
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(GIT_BRANCH "")
set(GIT_COMMIT_HASH "")
endif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS "VibraniumCore current branch: ${GIT_BRANCH}")
message(STATUS "VibraniumCore Version: ${GIT_VERSION}")
message(STATUS "VibraniumCore commit hash: ${GIT_COMMIT_HASH}")
message(STATUS "Released on: ${GIT_RELEASED_ON}")
message(STATUS "Generating version.h")
configure_file(
${CMAKE_SOURCE_DIR}/cmake/version.h.in
${CMAKE_SOURCE_DIR}/Source/Common/Version.h
)
find_package(Boost 1.72.0)
find_package(Threads)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
add_definitions(-DGIT_BRANCH="${GIT_BRANCH}")
add_definitions(-DGIT_VERSION="${GIT_VERSION}")
add_definitions(-DGIT_RELEASED_ON="${GIT_RELEASED_ON}")
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
include_directories(${Boost_INCLUDE_DIR})
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 64 bits")
if (WIN32)
set(WINXXBITS Win64)
endif(WIN32)
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 32 bits")
if (WIN32)
set(WINXXBITS Win32)
endif(WIN32)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(MySQL REQUIRED)
if(WIN32)
find_package(Flatbuffers REQUIRED
PATHS ${FLATBUFFERS_LOCATION})
else()
find_package(Flatbuffers REQUIRED
PATHS /usr/local/flatbuffers)
endif()
include_directories(${MYSQL_INCLUDE_DIR})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Common)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/WorldServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/AuthServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/ClientEmulator)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Game)
add_subdirectory(Tests)
set_target_properties(VibraniumCoreTests PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(
Common WorldServer AuthServer ClientEmulator Game
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
Here is my Common CMakeLists.txt:
file(GLOB flatBufferFiles_SRC
"Server/Packets/*/*.h"
"Server/Packets/*/*.cc"
)
add_library(
Common
SHARED
Config.cpp
Config.h
Logger.cpp
Logger.h
Database/MySQLConnection.h
Database/MySQLConnection.cpp
Database/MySQLTable.h
Database/MySQLTable.cpp
Banner.cpp
Banner.h
Database/MySQLTableBase.cpp
Database/MySQLTableBase.h
Memory/Memory.cpp
Memory/Memory.h
Server/Server.cpp
Server/Server.h
Server/Client.cpp
Server/Client.h
Server/Client.cpp
Server/Client.h
DataSchemas/Account.h
DataSchemas/AccountRole.h
${flatBufferFiles_SRC}
Helpers/Timer.h
Crypto/sha512.h
Server/Packet.cpp Server/Packet.h Server/Protocol/ServerOpcode.h Server/Protocol/ClientOpcode.h Server/Protocol/Opcodes.cpp Server/Protocol/Opcodes.h Server/WorldSession.cpp Server/WorldSession.h Server/AuthSession.cpp Server/AuthSession.h)
target_include_directories(Common PUBLIC ${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include ${FLATBUFFERS_LOCATION}/include)
target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${MYSQL_LIBRARY} ${CMAKE_CURRENT_SOURCE_DIR}/Server/Packets)
target_link_libraries(Common PUBLIC ${MYSQL_CONNECTOR_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
When I run cmake I get the following:
-- The C compiler identification is MSVC 19.24.28315.0
-- The CXX compiler identification is MSVC 19.24.28315.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - 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: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- VibraniumCore current branch: windows
-- VibraniumCore Version: 161
-- VibraniumCore commit hash: d8d564d
-- Released on: 2020-10-26 11:26:24 +0200
-- Generating version.h
-- Found Boost: C:/local/boost_1_72_0 (found suitable version "1.72.0", minimum required is "1.72.0")
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Target is 64 bits
-- New WorldServer Config file in will be installed in: E:/Vibranium-Core/cmake-build-debug/bin/configs
-- New AuthServer Config file in will be installed in: E:/Vibranium-Core/cmake-build-debug/bin/configs
-- Found PythonInterp: C:/Program Files (x86)/Python38-32/python.exe (found version "3.8.5")
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Vibranium-Core/cmake-build-debug
[Finished]
So boost is found. However when I try to build I get the following error:
====================[ Build | AuthServer | Debug ]==============================
"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe" --build E:\Vibranium-Core\cmake-build-debug --target AuthServer
[ 4%] Linking CXX shared library ..\..\bin\Common.dll
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1424~1.283\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\Common.dir\objects1.rsp /out:..\..\bin\Common.dll /implib:..\..\bin\lib\Common.lib /pdb:E:\Vibranium-Core\cmake-build-debug\bin\Common.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL C:\Program Files\MySQL\Connector C++ 8.0\lib64\vs14\mysqlcppconn8.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\Common.dir/intermediate.manifest CMakeFiles\Common.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc142-mt-gd-x64-1_72.lib'
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
I checked and I have this file libboost_date_time-vc142-mt-gd-x64-1_72.lib it is located in C:\local\boost_1_72_0\lib64-msvc-14.2
Also when I do :
message("BOOST LIBRARIES LOCATION: " ${Boost_LIBRARIES})
It comes up BOOST LIBRARIES LOCATION: so this variable on Windows ${Boost_LIBRARIES} is empty. Why is that and why it works on Linux but not on Windows ?
Most but not all Boost libraries are header only. Boost date_time is not therefore it needs to be added to your find_package command for Boost.
find_package(Boost 1.72.0 COMPONENTS date_time)
This will find the Boost DLLs on windows.
If you are interested in the static libraries you need to add
set(Boost_USE_STATIC_LIBS ON)
before your find_package_command.
After applying the changes to your CMakeLists.txt file clear the CMake cache, i.e. delete the CMakeCache.txt file in your build directory and rerun CMake.
If you are using Visual Studio, Have you tried using Tools / NuGet Package Manager to install boost_program_options-vc142? That worked for me.
I'm trying to start a project with CUDA C++ using CLion as an IDE.
I installed a fresh version of CUDA Developer Tools (v10.2) and tried to load the changes of the MakeFile.
Apparently, the CUDA compiler (nvcc) doesn't get properly linked, but I'm not sure this is the problem.
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(test_cuda LANGUAGES CXX CUDA)
find_package(CUDA)
set(CMAKE_CXX_STANDARD 17)
add_executable(test_cuda main.cu)
The result I get is the following:
"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" <path_to_project>\test_cuda
-- The CUDA compiler identification is NVIDIA 10.2.89
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe -- broken
CMake Error at E:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: <path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_5cf15\fast && "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_5cf15.dir\build.make /nologo -L CMakeFiles\cmTC_5cf15.dir\build
Building CUDA object CMakeFiles/cmTC_5cf15.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v10.2\bin\nvcc.exe -D_WINDOWS -Xcompiler=" /GR /EHsc" -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -x cu -c <path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\main.cu -o CMakeFiles\cmTC_5cf15.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_5cf15.dir\,-FS
main.cu
Linking CUDA executable cmTC_5cf15.exe
"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_5cf15.dir --rc=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\mt.exe --manifests -- C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo "CMakeFiles\cmTC_5cf15.dir\main.cu.obj" #<path_to_appdata>\Local\Temp\nm8647.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo CMakeFiles\cmTC_5cf15.dir\main.cu.obj /out:cmTC_5cf15.exe /implib:cmTC_5cf15.lib /pdb:<path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\cmTC_5cf15.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64 cudadevrt.lib cudart_static.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_5cf15.dir/intermediate.manifest CMakeFiles\cmTC_5cf15.dir/manifest.res" failed (exit code 1112) with the following output:
CMakeFiles\cmTC_5cf15.dir\main.cu.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
NMAKE : fatal error U1077: '"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeOutput.log".
See also "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeError.log".
[Finished]
Where I substitute the path to the project folder with <path_to_project>.
The .cu file is just a simple hello world source file for now, since I'm trying to solve the issue with the CUDA compiler first.
I can't really find any way to solve this.
Thank you a lot in advance.
The message module machine type 'x64' conflicts with target machine type 'X86' is the crux of the problem. This indicates you have a 32-bit vs 64-bit architecture mismatch. Please be sure you use consistent project and compiler settings.
So, if you are compiling for a 64-bit architecture, make sure your project (CMake) settings are configured to build x64 targets. Also, you must be sure to use the 64-bit versions of the compilation tools (nvcc). Specifically for your case, your linker flags appear to contain /machine:X86, which would need to be removed if you are aiming for a 64-bit build. This can likely be configured through the CLion IDE in your Toolchain settings.
I'm using CLion and CMake to link with Boost and as toolchain I chose the MSVC compiler:
My architecture is configured as amd64 since I'm running a 64-bit system (the default of x86 only tries to find the 32-bit versions of Boost which I don't want).
Furthermore I compiled the 64-bit libraries using this guide. I setup my CMake file respectively:
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
set(BOOST_LIBRARYDIR "C:/local/boost_1_69_0_b1_rc3/stage/x64/lib")
set(BOOST_INCLUDEDIR "C:/local/boost_1_69_0_b1_rc3/boost")
My main.cpp compiles just fine but I'm getting a linker error:
====================[ Build | BoostTesting | Debug ]============================
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe --build D:\Cpp\BoostTesting\cmake-build-debug --target BoostTesting --
[ 50%] Linking CXX executable BoostTesting.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~3\2017\ENTERP~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\BoostTesting.dir\objects1.rsp /out:BoostTesting.exe /implib:BoostTesting.lib /pdb:D:\Cpp\BoostTesting\cmake-build-debug\BoostTesting.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_filesystem-vc141-mt-gd-x64-1_69.lib C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_system-vc141-mt-x64-1_69.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\BoostTesting.dir/intermediate.manifest CMakeFiles\BoostTesting.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_iostreams-vc141-mt-gd-x64-1_69.lib'
NMAKE : fatal error U1077: 'C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
When using x86_amd64 as architecture it also fails to link. The other architectures don't make sense for my PC:
Using the pre-compiled binaries from here also fails to link. How to fix this linking problem?
Just setting BOOST_ROOT in CMakeLists.txt
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
and using amd64 as the architecture surprisingly did the trick now. Using MSVC with CMake is better supported with Visual Studio (quite obviously) and linking to Boost was no issue anymore. Now the build also works from CLion but Visual Studio should be preferred until CLion maybe gets better MSVC integration.
I am trying to compile a very simple test program on Windows and keep getting linker errors. The program to link is the following:
#include <boost/asio/io_context.hpp>
int main()
{
boost::asio::io_context context;
}
While the CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(windows-test)
SET(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.6.7 COMPONENTS system)
include_directories("${Boost_INCLUDE_DIRS}")
add_executable(windows-test main.cpp)
target_link_libraries(windows-test Boost::system)
When building this using nmake, it fails with the following output:
-- Boost version: 1.67.0
-- Found the following Boost libraries:
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: Z:/windows-test/build
[ 50%] Linking CXX executable windows-test.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1414~1.264\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\windows-test.dir\objects1.rsp /out:windows-test.exe /implib:windows-test.lib /pdb:Z:\windows-test\build\windows-test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_67_0\lib64-msvc-14.1\boost_system-vc141-mt-gd-x64-1_67.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\windows-test.dir/intermediate.manifest CMakeFiles\windows-test.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_system-vc141-mt-gd-x64-1_67.lib'
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
The file 'libboost_system-vc141-mt-gd-x64-1_67.lib' indeed does not exist on the system, but I don't know where it is coming from, since it does not appear on the linker command that it is executing. The linker command shows the file C:\local\boost_1_67_0\lib64-msvc-14.1\boost_system-vc141-mt-gd-x64-1_67.lib, which does exist.
Why oh why does it try to link to a missing file, that appears nowhere on the linker command? I feel way out of my depth here, since I haven't had to use Windows for almost 20 years and never before had to port to it.
Boost headers contain linker commands on Windows, so that Boost libraries are linked automatically when including the appropriate header. However, it seems your setup uses a different naming scheme for the libraries, which makes these fail to link.
You can disable the Boost auto-linking feature by defining the preprocessor macro BOOST_ALL_NO_LIB. Like this:
target_compile_definitions(windows-test PRIVATE BOOST_ALL_NO_LIB)