无法使用cmake编译SFML项目

时间:2017-08-29 10:39:15

标签: windows cmake sfml

我正在尝试在Windows上使用cmake / g ++建立一个新的c ++ / sfml项目,但是构建仍然因链接错误而失败。如果我使用SFML_STATIC,仍然会出现错误。我已经查找了问题但到目前为止没有一个答案消除了这些错误。

- \build
- \cmake_modules
  - FindSFML.cmake
- \SFML
- CMakeLists.txt
- config.h.in
- main.cpp

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
project(myproject)

set(myproject_VERSION_MAJOR 1)
set(myproject_VERSION_MINOR 0)
configure_file(
    "${PROJECT_SOURCE_DIR}/config.h.in"
    "${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")

set(EXECUTABLE_NAME "myproject")


set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/SFML")
find_package(SFML 2 REQUIRED network audio graphics window system)
include_directories(${SFML_INCLUDE_DIR})
add_executable(${EXECUTABLE_NAME} main.cpp)
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})

install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)

include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VERSION_MAJOR "${myproject_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${myproject_VERSION_MINOR}")
include(CPack)

输出 -

-- Found SFML 2.4.2 in C:/Users/[project dir]/SFML/include
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/[project dir]/build
Scanning dependencies of target myproject
[ 50%] Building CXX object CMakeFiles/myproject.dir/main.cpp.obj
[100%] Linking CXX executable myproject.exe
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xf5): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x11b): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x157): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x18d): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x19e): undefined reference to `_imp___ZN2sf5Color5GreenE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1a8): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1c8): undefined reference to `_imp___ZN2sf6Window5closeEv'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1dd): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x20f): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x22a): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x23d): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x251): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x263): undefined reference to `_imp___ZN2sf6Window7displayEv'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x272): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x29b): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2c2): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2fc): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0xe): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x1c): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
CMakeFiles\myproject.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x2c): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\myproject.dir\build.make:101: recipe for target 'myproject.exe' failed
mingw32-make[2]: *** [myproject.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/myproject.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/myproject.dir/all] Error 2
Makefile:150: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

0 个答案:

没有答案