Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 无法使用cmake编译SFML项目_Windows_Cmake_Sfml - Fatal编程技术网

Windows 无法使用cmake编译SFML项目

Windows 无法使用cmake编译SFML项目,windows,cmake,sfml,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(VERS

我正在尝试在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

SFML_库
是否包含任何内容?将其添加到cmake:message(状态“Library(SFML_库):${SFML_库}”)调试;C:/Users/[project dir]/SFML/lib/SFML-network-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-network.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-audio-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-audio.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-graphics-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-graphics.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-window-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-window.lib;调试;C:/Users/[project dir]/cmake/SFML/lib/SFML-system-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-system.lib@arrow您是否尝试链接来自MinGW构建的MSVC二进制文件?那不行。您将需要与所使用的编译器和版本完全匹配的二进制文件。SFML是C++库,C++接口在不同编译器工具链或版本之间一般不兼容。这能回答你的问题吗?
SFML_库
是否包含任何内容?将其添加到cmake:message(状态“Library(SFML_库):${SFML_库}”)调试;C:/Users/[project dir]/SFML/lib/SFML-network-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-network.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-audio-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-audio.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-graphics-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-graphics.lib;调试;C:/Users/[project dir]/SFML/lib/SFML-window-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-window.lib;调试;C:/Users/[project dir]/cmake/SFML/lib/SFML-system-d.lib;优化;C:/Users/[project dir]/SFML/lib/SFML-system.lib@arrow您是否尝试链接来自MinGW构建的MSVC二进制文件?那不行。您将需要与所使用的编译器和版本完全匹配的二进制文件。SFML是C++库,C++接口在不同编译器工具链或版本之间一般不兼容。这能回答你的问题吗?