我正在尝试在 Linux 上使用 CLion IDE,并且正在迁移我的 SFML 应用程序。它坚持我使用我目前遇到问题的 CMake。
cmake_minimum_required(VERSION 2.6)
project(SFML2)
include_directories("${PROJECT_BINARY_DIR} src/")
include_directories("${YOUR_DIRECTORY} src")
# Define sources and executable
set(EXECUTABLE_NAME "SFML")
add_executable(${EXECUTABLE_NAME} src/SFML.cpp)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules"
${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
# CPack packaging
include(InstallRequiredSystemLibraries)
但是我不断收到构建错误
CMakeFiles/SFML.dir/src/SFML.cpp.o: In function `main':
SFML.cpp:(.text+0xca): undefined reference to `Game::Game()'
SFML.cpp:(.text+0xd9): undefined reference to `Game::run()'
CMakeFiles/SFML.dir/src/SFML.cpp.o: In function `Game::~Game()':
SFML.cpp:(.text._ZN4GameD2Ev[_ZN4GameD5Ev]+0xa2): undefined reference to `Player::~Player()'
SFML.cpp:(.text._ZN4GameD2Ev[_ZN4GameD5Ev]+0xb4): undefined reference to `Player::~Player()'
SFML.cpp:(.text._ZN4GameD2Ev[_ZN4GameD5Ev]+0x18b): undefined reference to `Player::~Player()'
SFML.cpp:(.text._ZN4GameD2Ev[_ZN4GameD5Ev]+0x1a2): undefined reference to `Player::~Player()'
collect2: error: ld returned 1 exit status
CMakeFiles/SFML.dir/build.make:90: recipe for target 'SFML' failed
make[2]: *** [SFML] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/SFML.dir/all' failed
make[1]: *** [CMakeFiles/SFML.dir/all] Error 2
Makefile:136: recipe for target 'all' failed
make: *** [all] Error 2
游戏参考与 SFML.cpp 位于同一位置,这是所有内容的启动位置。
这目前在 Eclipse CDT 中没有问题