1

Here is my main CmakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(Vibranium_Core)

set(CMAKE_CXX_STANDARD 14)

find_package(Boost 1.72.0)

if(NOT Boost_FOUND)
    message(FATAL_ERROR "Could not find boost!")
endif()
include_directories(${Boost_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)

set_target_properties(
        Common WorldServer AuthServer
        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: /Source/Common/CmakeLists.txt:`

add_library(Common SHARED Config.cpp Config.h Logger.cpp Logger.h)
target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

When I try to build my project I get:

NMAKE : fatal error U1073: don't know how to make 'bin\lib\Common.lib'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\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.24.28314\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

I have this problem only on Windows. When I try to build the project on Linux there is no issue. What is causing this problem and how can I fix it?

Venelin
  • 2,905
  • 7
  • 53
  • 117
  • I guess `Common` library target is created in `Source/Common/CMakeLists.txt` which you included with `add_subdirectory`. Probably, setting `LIBRARY_OUTPUT_DIRECTORY` property in the main `CMakeLists.txt` after the target is created doesn't work well. If you want to create **all** libraries under specific directory, then instead set **variable** `CMAKE_LIBRARY_OUTPUT_DIRECTORY`. This setting should come before `add_subdirectory`. – Tsyvarev Aug 22 '20 at 13:50
  • Also, in case `Common` is a **shared** library, make sure you have **exported** at least some symbols from it. Otherwise `.lib` file won't be created, see that question: https://stackoverflow.com/questions/1941443/cmake-linking-against-shared-library-on-windows-error-about-not-finding-lib-fi. – Tsyvarev Aug 22 '20 at 13:52
  • Is it just me, or Visual Studio is so hard to use with CMake? – J. Bailleul Jun 25 '21 at 09:46

0 Answers0