简体   繁体   English

有没有一种从 Linux 安装交叉编译 SFML 的好方法

[英]Is there a good way to cross-compile SFML for windows from a Linux install

So I have been making an application in SFML and my friend wanted to try it out on his windows machine(he's not too tech savy so he couldn't compile it himself, though not for lack of trying).所以我一直在 SFML 中制作一个应用程序,我的朋友想在他的 windows 机器上尝试一下(他不太懂技术,所以他不能自己编译它,虽然不是因为缺乏尝试)。 I figured that I'd just compile my program with MinGW and send him an executable, problem is, when I try to run the application I get the following message:我想我只是用 MinGW 编译我的程序并向他发送一个可执行文件,问题是,当我尝试运行应用程序时,我收到以下消息:

009c:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\wineusb": c0000142
00ec:err:module:import_dll Library sfml-graphics-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00ec:err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00ec:err:module:import_dll Library sfml-window-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00ec:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00ec:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00ec:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe" failed, status c0000135

So Ignoring the first error I can see that the program wants dll files to be attached to it.所以忽略第一个错误,我可以看到程序想要附加 dll 文件。 Problem is I don't know how to do that and this is where I have run into hurdles for every way I've tried to compile this thing.问题是我不知道该怎么做,这就是我试图编译这个东西的每一种方式都遇到障碍的地方。 I've tried to link the dlls as libraries (for which I switched to cmake, cause even though I don't like using it, I wouldn't have to type a memoir into the terminal).我试图将 dll 链接为库(为此我切换到 cmake,因为即使我不喜欢使用它,我也不必在终端中输入回忆录)。 I have what seems to be a decent windows toolchain from the web but when I tried to link the dll files with:我有似乎是来自网络的不错的 Windows 工具链,但是当我尝试将 dll 文件链接到:

target_link_libraries (SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/openal32.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-audio-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-graphics-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-network-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-system-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-window-2.dll)

This gives a different error of:这给出了一个不同的错误:

MAKE_TOOLCHAIN_FILE=windows.cmake CMakeLists.txt
CMake Error at CMakeLists.txt:8 (target_link_libraries):
  Cannot specify link libraries for target
  "SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/openal32.dll"
  which is not built by this project.


-- Configuring incomplete, errors occurred!
See also "/home/kyle/Documents/tileMapEditor/Windows/CMakeFiles/CMakeOutput.log".

I'm sorry if this in in any way incoherent or is lacking information.如果这以任何方式不连贯或缺乏信息,我很抱歉。 I've been working on compiling this for a week and have tried installing windows and compiling it there.我已经为此编译了一个星期,并尝试安装 Windows 并在那里编译它。 (That sucked! I hate GUIs as options move and it takes forever to find out where they moved) I went back to CMake but I don't ever use CMake as I just use raw g++, so I wound up using CMake off of various online posts (CMake's guide sucks btw). (这太糟糕了!我讨厌 GUI,因为选项会移动,而且要花很长时间才能找到它们移动的位置)我回到了 CMake,但我从不使用 CMake,因为我只使用原始 g++,所以我最终使用了各种 CMake在线帖子(顺便说一句,CMake 的指南很烂)。

To Clarify the question is if there is a decent way to compile this.澄清问题是是否有一种体面的方法来编译它。 I will use CMake or the command line, I just need to get it to compile for windows and run in wine.我将使用 CMake 或命令行,我只需要让它为 windows 编译并在 wine 中运行。

========================================================================= ==================================================== ========================

UPDATE: I've tried to copy the dll files over to the project folder but that was not the end of my problems.更新:我试图将 dll 文件复制到项目文件夹中,但这并不是我的问题的结束。 I rebuilt the game and I now get this huge list of errors:我重建了游戏,现在我得到了这个巨大的错误列表:

008c:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\wineusb": c0000142
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-graphics-2.dll") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library sfml-window-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-graphics-2.dll") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-graphics-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-graphics-2.dll") not found
00f0:err:module:import_dll Library sfml-graphics-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-system-2.dll") not found
00f0:err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\sfml-window-2.dll") not found
00f0:err:module:import_dll Library sfml-window-2.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00f0:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00f0:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe") not found
00f0:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\kyle\\Documents\\tileMapEditor\\Windows\\build\\TOSTE.exe" failed, status c0000135

Is there something big I'm missing here?我在这里缺少什么重要的东西吗? My CMakeLists.txt is as follows:我的 CMakeLists.txt 如下:

cmake_minimum_required(VERSION 3.22)

project(TOSTE)

add_executable(TOSTE Main.cpp userInterface.cpp userInterface.hpp tileRenderer.cpp tileRenderer.hpp Button.cpp Button.hpp)

target_link_libraries (TOSTE sfml-graphics sfml-window sfml-system)
target_link_libraries (SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/openal32.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-audio-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-graphics-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-network-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-system-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-window-2.dll

The tool chain I am using contains the following:我使用的工具链包含以下内容:

set(CMAKE_SYSTEM_NAME Windows)
    set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

    # cross compilers to use for C, C++ and Fortran
    set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
    set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
    set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
    set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

    # target environment on the build host system
    set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

    # modify default behavior of FIND_XXX() commands
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

I am really hoping there is a better way of doing this, as it is really gross.我真的希望有更好的方法来做到这一点,因为它真的很恶心。 I'm also tempted to just use a compatibility tool to run the app on windows as the version I have now should work for MacOS and Linux.我也很想只使用兼容性工具在 Windows 上运行应用程序,因为我现在拥有的版本应该适用于 MacOS 和 Linux。

Windows expects DLL files to be placed either in the PATH directory or in the same directory as the executable. Windows 期望将 DLL 文件放置在 PATH 目录中或与可执行文件相同的目录中。
If you want your DLLs to be placed in a different directory, you should add it to the PATH.如果您希望将 DLL 放在不同的目录中,则应将其添加到 PATH。 When running your program with Wine, you can do that by setting the variable WINEPATH :使用 Wine 运行程序时,可以通过设置变量WINEPATH

WINEPATH=/path/to/dlls ./TOSTE.exe WINEPATH=/path/to/dlls ./TOSTE.exe

Building with CMake使用 CMake 构建

You are calling target_link_libraries wrong.您调用target_link_libraries是错误的。 As the name suggests, it expects a CMake target as the first arguments.顾名思义,它需要一个 CMake 目标作为第一个参数。 So instead of所以而不是

target_link_libraries (SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/openal32.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-audio-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-graphics-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-network-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-system-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-window-2.dll)

you should do你应该做

target_link_libraries (MY_PROGRAM_TARGET SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/openal32.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-audio-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-graphics-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-network-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-system-2.dll SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/sfml-window-2.dll)

You can also make it shorter by supplying the link_directory, which is您还可以通过提供 link_directory 来缩短它,它是

"SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/" “SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/”

in your case.在你的情况下。

target_link_directories(MY_PROGRAM_TARGET PRIVATE SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit/SFML-2.5.1/bin/)
target_link_libraries(MY_PROGRAM_TARGET openal32 sfml-audio sfml-graphics sfml-network sfml-system sfml-window)

If you want all the linked DLLs to be copied to your executable's directory, you can use the TARGET_RUNTIME_DLLS generator expression added to CMake 3.21.如果您希望将所有链接的 DLL 复制到可执行文件的目录中,可以使用添加到 CMake 3.21 的TARGET_RUNTIME_DLLS生成器表达式。

add_custom_command(TARGET MY_PROGRAM_TARGET POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:MY_PROGRAM_TARGET> $<TARGET_FILE_DIR:MY_PROGRAM_TARGET>
  COMMAND_EXPAND_LISTS
  )

It only supports Windows DLLs at the moment.它目前仅支持 Windows DLL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM