CMake-致命错误U1073:不知道如何制作特定的库 [英] Cmake - fatal error U1073: don't know how to make a specific library
问题描述
我正在尝试在Windows下构建我的项目.在Linux上没有问题.
I am trying to build my project under Windows. On Linux it has no issues.
这是我的主要 CMakeLists.txt
:
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")
set(Boost_USE_STATIC_LIBS ON)
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 COMPONENTS date_time serialization regex)
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}")
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"
)
这里是 AuthServer
CMakeLists.txt:
Here is AuthServer
CMakeLists.txt:
add_executable(AuthServer
AuthServer.cpp
${PRIVATE_SOURCES}
../Database/Implementation/LoginDatabase.cpp
../Database/Implementation/LoginDatabase.h
../Database/Implementation/LoginDatabase/Accounts.h
../Database/Implementation/LoginDatabase/AccountRoles.h
../Database/Implementation/LoginDatabase/Accounts.cpp
../Database/Implementation/LoginDatabase/AccountRoles.cpp
../Memory/LoginMemory.h
../Memory/LoginMemory.cpp
AuthServer.h
Server/AuthServerOpcodes.cpp Server/AuthServerOpcodes.h)
target_include_directories(AuthServer PUBLIC ../Database ../Database/Implementation/LoginDatabase/ ../../Game)
target_link_libraries(AuthServer PUBLIC Common Game ${Boost_LIBRARIES})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/bin/configs/)
message(STATUS "Configs folder will be created: ${CMAKE_BINARY_DIR}/bin/configs")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/configs/)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/bin/configs/AuthServer.conf)
message(STATUS "New AuthServer Config file in will be installed in: ${CMAKE_BINARY_DIR}/bin/configs")
add_custom_command(
TARGET AuthServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/AuthServer.conf.dist
${CMAKE_BINARY_DIR}/bin/configs/AuthServer.conf)
endif()
这是我的游戏库 CMakeLists.txt
:
add_library(
Game
SHARED
Accounts/AccountManager.cpp Accounts/AccountManager.h)
target_include_directories(Game PUBLIC /usr/local/mysql/connector-c++-/include)
target_include_directories(Game PUBLIC . ${MYSQL_LIBRARY})
target_include_directories(Game PUBLIC ../Core/AuthServer)
target_include_directories(Game PUBLIC ../Core/WorldServer)
target_link_libraries(Game PUBLIC ${MYSQL_CONNECTOR_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} Common)
当我尝试构建时,我得到以下输出和错误:
When I try to build I get this output and 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
Scanning dependencies of target Common
[ 4%] Building CXX object Source/Common/CMakeFiles/Common.dir/Config.cpp.obj
Config.cpp
[ 8%] Building CXX object Source/Common/CMakeFiles/Common.dir/Logger.cpp.obj
Logger.cpp
[ 13%] Building CXX object Source/Common/CMakeFiles/Common.dir/Database/MySQLConnection.cpp.obj
MySQLConnection.cpp
[ 17%] Building CXX object Source/Common/CMakeFiles/Common.dir/Database/MySQLTable.cpp.obj
MySQLTable.cpp
[ 21%] Building CXX object Source/Common/CMakeFiles/Common.dir/Banner.cpp.obj
Banner.cpp
[ 26%] Building CXX object Source/Common/CMakeFiles/Common.dir/Database/MySQLTableBase.cpp.obj
MySQLTableBase.cpp
[ 30%] Building CXX object Source/Common/CMakeFiles/Common.dir/Memory/Memory.cpp.obj
Memory.cpp
[ 34%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/Server.cpp.obj
Server.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[ 39%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/Client.cpp.obj
Client.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[ 43%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/Packet.cpp.obj
Packet.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[ 47%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/Protocol/Opcodes.cpp.obj
Opcodes.cpp
[ 52%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/WorldSession.cpp.obj
WorldSession.cpp
[ 56%] Building CXX object Source/Common/CMakeFiles/Common.dir/Server/AuthSession.cpp.obj
AuthSession.cpp
[ 60%] Linking CXX shared library ..\..\bin\Common.dll
Creating library ..\..\bin\lib\Common.lib and object ..\..\bin\lib\Common.exp
Creating library ..\..\bin\lib\Common.lib and object ..\..\bin\lib\Common.exp
[ 60%] Built target Common
Scanning dependencies of target Game
[ 65%] Building CXX object Source/Game/CMakeFiles/Game.dir/Accounts/AccountManager.cpp.obj
AccountManager.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[ 69%] Linking CXX shared library ..\..\bin\Game.dll
[ 69%] Built target Game
Scanning dependencies of target AuthServer
[ 73%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/AuthServer.cpp.obj
AuthServer.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[ 78%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/__/Database/Implementation/LoginDatabase.cpp.obj
LoginDatabase.cpp
[ 82%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/__/Database/Implementation/LoginDatabase/Accounts.cpp.obj
Accounts.cpp
[ 86%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/__/Database/Implementation/LoginDatabase/AccountRoles.cpp.obj
AccountRoles.cpp
[ 91%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/__/Memory/LoginMemory.cpp.obj
LoginMemory.cpp
[ 95%] Building CXX object Source/Core/AuthServer/CMakeFiles/AuthServer.dir/Server/AuthServerOpcodes.cpp.obj
AuthServerOpcodes.cpp
NMAKE : fatal error U1073: don't know how to make 'bin\lib\Game.lib'
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.
我有两个问题:
- 为什么我会看到此消息
请适当定义_WIN32_WINNT或_WIN32_WINDOWS.
,该如何解决?我只能在Windows上看到它.在Linux上,它不会消失. - 如何解决错误
NMAKE:致命错误U1073:不知道如何制作'bin \ lib \ Game.lib'
?
- Why I see this message
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
and how can I fix it? I see this only on Windows. On Linux it does not apepar. - How can I fix the error
NMAKE : fatal error U1073: don't know how to make 'bin\lib\Game.lib'
?
P.S.这是我在构建目录中的内容:
P.S. Here is what I have in the build dir:
推荐答案
已
第二次查看时,我不确定问题#2.我必须有权访问您的更多代码库.
I'm not sure about issue #2 upon second viewing. I'd have to have access to more of your codebase.
但是我想我可以回答#1.
But I think I can answer #1.
#1.)这是来自boost的消息:带有Boost的D_WIN32_WINNT编译器警告
#1.) This is a message from boost: D_WIN32_WINNT compiler warning with Boost
要解决第1个问题,您应该包括一个特定的Windows标头文件.在您的顶级源代码中添加以下行.正如希尔在用户链接中所指定的那样.
To fix issue number 1 you should include a specific windows header file. Add following line in your top source code. As was specified by user Hill in the post I linked.
#include <SDKDDKVer.h>
这将适当地定义_WIN32_WINNT.
This will define _WIN32_WINNT appropriately.
尝试修复#2的想法.
使用其他生成器.我不建议使用Nmake,因为它反而非常慢,并且给出的错误消息少于恒星.我建议使用Visual Studio或Ninja.
Use a different generator. I don't recommmend Nmake because it is super slow anyway and gives less than stellar error messages. I'd recommend Visual Studio or Ninja.
这篇关于CMake-致命错误U1073:不知道如何制作特定的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!