简体   繁体   English

SFML构建所有批处理文件

[英]SFML build all batch file

I was wondering if there was a way to alter the below code so it will build all the ".cpp" and ".h" files in a folder (+ subfolders) and specify one .exe name to be made. 我想知道是否有一种方法可以更改以下代码,以便它将在文件夹(+子文件夹)中构建所有“ .cpp”和“ .h”文件并指定一个.exe名称。

@ECHO OFF
echo Building...
g++ -DSFML_STATIC main.cpp -lsfml-graphics-s -lsfml-window-s -lsfml-system-s

I know I can use CMake, but I want to know if it's possible with a batch script. 我知道我可以使用CMake,但是我想知道是否可以使用批处理脚本。 If I can't do what I'm asking, can I at least specify a name for the .exe? 如果我无法完成所要询问的内容,是否可以至少为.exe指定名称? It always comes out as "a.exe". 它总是以“ a.exe”的形式出现。 I am using MingW. 我正在使用MingW。

Sorry, if this has been covered already. 抱歉,如果已经解决了。 I searched and didn't find anything. 我搜索了,没有找到任何东西。

"a.exe" is the default name that g++ uses for executables on Windows. “ a.exe”是g ++在Windows上用于可执行文件的默认名称。 If you want to specify your own name, add "-o foo.exe" to the g++ command line. 如果要指定自己的名称,请在g ++命令行中添加“ -o foo.exe”。

To specify the name for the output file, add option "-o name.exe". 要指定输出文件的名称,请添加选项“ -o name.exe”。

To pass a large number of files to g++, you will have to use a response file like so: 要将大量文件传递给g ++,您将必须使用如下响应文件:

@echo off
setlocal enabledelayedexpansion
for /r %%f in (*.cpp) do (
    set a=%%f
    set a=!a:\=/!
    echo !a! >>files.tmp
)
endlocal
g++ -DSFML_STATIC @files.tmp -o bob.exe -lsfml-graphics-s -lsfml-window-s -lsfml-system-s
del files.tmp

Note that you should only give the *.cpp files to g++. 请注意,您只应将* .cpp文件提供给g ++。 It will find the .h files on its own while compiling. 编译时,它将自行找到.h文件。

I don't have a MingW setup so I wasn't able to test this completely, sorry. 我没有MingW设置,所以无法完全测试一下。 But the part about building the response file works at least. 但是至少有关构建响应文件的部分有效。

Sources: 资料来源:

[ http://www.mingw.org/wiki/MinGW_for_First_Time_Users_HOWTO] [ http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true] [ Multiple do commands in a for loop: Echoing a string to a file and then redirecting to the command window [ http://www.mingw.org/wiki/MinGW_for_First_Time_Users_HOWTO] [ http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true] [ for循环中的多个do命令:将字符串回显到文件,然后重定向到命令窗口

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

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