Batch file 在批处理文件的单个变量中添加所有cpp文件名

Batch file 在批处理文件的单个变量中添加所有cpp文件名,batch-file,Batch File,因此,我使用g++并希望生成一个.bat文件,该文件使用我文件夹中的所有.cpp来编译它们。 问题是,我无法让保存文件名的变量保存找到的其他文件名。 我现在有这个: set objs= for /R %%f in (*.cpp) do set objs=!objs! %%f set cc=C:\MinGW\bin/g++.exe set include_paths=-IF:\SDL_Files\SDL2-2.0.4-mingw\i686-w64-mingw32\include\SDL2 -IF:

因此,我使用g++并希望生成一个.bat文件,该文件使用我文件夹中的所有.cpp来编译它们。 问题是,我无法让保存文件名的变量保存找到的其他文件名。 我现在有这个:

set objs=
for /R %%f in (*.cpp) do set objs=!objs! %%f
set cc=C:\MinGW\bin/g++.exe
set include_paths=-IF:\SDL_Files\SDL2-2.0.4-mingw\i686-w64-mingw32\include\SDL2 -IF:\SDL_Files\SDL2_image-2.0.1\i686-w64-mingw32\include\SDL2
set library_paths=-LF:\SDL_Files\SDL2-2.0.4-mingw\i686-w64-mingw32\lib -LF:\SDL_Files\SDL2_image-2.0.1\i686-w64-mingw32\lib
set compiler_flags=-w -Wl,-subsystem,windows -fno-exceptions
set linker_flags=-lmingw32 -lSDL2main -lSDL2 -lSDL2_image
set obj_name=bullshit
@echo on
%cc% %objs% %include_paths% %library_paths% %compiler_flags% %linker_flags% -o %obj_name%

pause
我没有错过太多,但它阻碍了我,我找不到答案…

试试:

set objs=
for /R %%f in (*.cpp) do call set objs=%%objs%% %%f
如果不调用for循环,它只会覆盖%obj%,而不是附加到它

%%objs%%是必需的,因为调用传递时%%被解释为%(%%是转义的%字符)

尝试:

set objs=
for /R %%f in (*.cpp) do call set objs=%%objs%% %%f
如果不调用for循环,它只会覆盖%obj%,而不是附加到它

%%objs%%是必需的,因为在调用传递时%%被解释为%(%%是转义的%字符)