简体   繁体   中英

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.

@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. If I can't do what I'm asking, can I at least specify a name for the .exe? It always comes out as "a.exe". I am using 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. If you want to specify your own name, add "-o foo.exe" to the g++ command line.

To specify the name for the output file, add option "-o name.exe".

To pass a large number of files to g++, you will have to use a response file like so:

@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++. It will find the .h files on its own while compiling.

I don't have a MingW setup so I wasn't able to test this completely, sorry. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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