在过去的几天里,我一直在到处搜索,似乎无法解决此问题,或者也许我只是不理解一些答案。
我有一个使用SFML构建的应用程序(精确地说是一个游戏),我设法在Linux 2.4.2版上进行了编译。我想迁移到2.5.1并能够在Windows上进行编译,所以我将CMakeLists.txt文件更改为:
cmake_minimum_required(VERSION 3.0)
# There is no real need for C++17 or 14, but I like to use up-to-date versions
if(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
if (WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/)
endif(WIN32)
# Includes
include_directories(include)
# Source files
set(SOURCE_FILES
source/main.cpp
source/Game.cpp
)
# Assets
set(ASSETS
assets/Fonts/xolonium.ttf
)
# Debug Mode
project(HexDebug VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE DEBUG) # This is ignored by MSVC
#SFML Package
find_package(SFML 2.5 CONFIG COMPONENTS system window graphics network audio REQUIRED)
if(SFML_FOUND)
set(SFML_STATIC_LIBRARIES TRUE)
if(WIN32)
set(SFML_USE_STATIC_STD_LIBS TRUE)
endif(WIN32)
endif(SFML_FOUND)
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Debug/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE -g -Wall -O0 -D_DEBUG)
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
#Release Mode
project(Hex VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE RELEASE) # This is ignored by MSVC
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Release/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE "-O3")
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
该cmake可以工作并生成VS解决方案,我可以使用msbuild构建该解决方案(请注意,我不想启动Visual Studio,而仅使用msbuild)。但是,一旦我尝试运行它,它会要求提供dll,而我并不想这样做。
我认为可以通过静态链接来解决(我对静态或动态链接了解不多),但仍然需要它们。
在此链接中,他们说我们不再需要包含$ {SFML_INCLUDE_DIR}和$ {SFML_LIBRARIES}:https://en.sfml-dev.org/forums/index.php?topic=24070.0
如何避免这种情况?我希望完全独立于DLL,或者至少能够包括从SFML编译和安装的二进制文件(由我编译而不是预编译)安装的bin目录。
谢谢。