0

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 ?

Venelin
  • 2,905
  • 7
  • 53
  • 117

2 Answers2

2

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.

vre
  • 6,041
  • 1
  • 25
  • 39
  • 1
    Why this is not required in Linux but in Windows only ? – Venelin Oct 26 '20 at 10:15
  • That's something I cannot explain. It might be that another component requires Boost::date_time too and the directory where the lib resides has already been defined to the linker. But that's a rough guess. – vre Oct 26 '20 at 10:29
  • Even with this I get the same error. Suggestion didn't changed anything. – Venelin Oct 26 '20 at 10:32
  • What does your `message("BOOST LIBRARIES LOCATION: " ${Boost_LIBRARIES})` outputs now? – vre Oct 26 '20 at 10:57
  • `BOOST LIBRARIES LOCATION: optimizedC:/local/boost_1_72_0/lib64-msvc-14.2/boost_date_time-vc142-mt-x64-1_72.libdebugC:/local/boost_1_72_0/lib64-msvc-14.2/boost_date_time-vc142-mt-gd-x64-1_72.lib` Thats it. – Venelin Oct 26 '20 at 11:01
  • It places some strange `optimized` infront. Should it be like that ? – Venelin Oct 26 '20 at 11:03
  • Then you need to add `set(Boost_USE_STATIC_LIBS ON)` in front of your find_package command. `optimized` is a keyword for Release build dependencies `debug` for Debug build dependencies. – vre Oct 26 '20 at 11:05
  • Again this word `optimized` appears. – Venelin Oct 26 '20 at 11:09
  • As most libraries are named differently for `debug` and `optimized` configurations you need to prefix them with these keywords. – vre Oct 26 '20 at 11:10
  • See last paragraph [here](https://cmake.org/cmake/help/latest/command/target_link_libraries.html?highlight=optimized#overview) for a detailed explanation of the keywords – vre Oct 26 '20 at 11:13
  • Thank you @vre Can you please check now this question as I crashed into another issue which I don't understand: https://stackoverflow.com/questions/64536047/cmake-fatal-error-u1073-dont-know-how-to-make-a-specific-library – Venelin Oct 26 '20 at 11:16
  • Faced the same problem, answers in this line didn't work, have no idea why it marked as "accepted" – Dmitrii Dec 21 '21 at 09:53
0

If you are using Visual Studio, Have you tried using Tools / NuGet Package Manager to install boost_program_options-vc142? That worked for me.

Skyfish
  • 119
  • 2
  • 4