我知道可能会有类似的问题,只是它们是在C++中的,我不知道它们是否相同。我有一些代码
void BuildApp(char *AppName)
{
char *cmd;
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/");
// Make the package dir.
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/DEBIAN");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/Applications");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/Applications/");
cmd = combine(cmd, AppName);
cmd = combine(cmd, ".app");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/Applications/");
cmd = combine(cmd, AppName);
cmd = combine(cmd, ".app/Inc");
system(cmd);
cmd = "";
cmd = combine("cp ./Projects/", AppName);
cmd = combine(cmd, "/Assets/app.icon.png ./Projects/");
cmd = combine(cmd, AppName);
cmd = combine(cmd, "/Package/Applications/");
cmd = combine(cmd, AppName);
cmd = combine(cmd, ".app/Icon.png");
system(cmd);
printf("Building application...");
cmd = "";
cmd = combine("cd ./Projects/", AppName);
system(cmd);
printf(cmd);
cmd = "";
cmd = combine("gcc App.c -o ", AppName);
printf(cmd);system(cmd);
system(cmd);
}
但它似乎执行不正常。这是在 Linux(实际上是 cygwin)上运行的,并使用 GCC 编译。出于某种原因,system();
应该执行 GCC 编译操作的函数在cd
命令之前执行,给我这个输出:
gcc: App.c: No such file or directory
gcc: no input files
Building application...
cd ./Projects/Sample
但是,在cd
声明之后(我打印出来检查它们执行的顺序),GCC 编译命令没有执行,给我留下一个未编译的 App.c,并且程序执行出错。任何有关为什么会发生这种情况的帮助将不胜感激。