如果文件名有空格,MinGw 不执行程序
MinGw doesn't execute the program if file name has spaces
所以我用notepad++的NppExec直接编译执行C++文件
npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)
一切正常,现在假设我有这段代码:
#include <iostream>
using namespace std;
int main() {
cout << "This is a normal statement" << endl;
cout << "This statement uses endl;" << endl;
cout << "This one has " << "multiple " << "chevrons" << "Cant tell huh?" << endl;
cout << "This is a flush statement, this does not break line like this :" << flush;
cout << "Me flush statement" << endl;
system("pause");
return 0;
}
我是用上面的执行代码编译的.....
好吧,如果文件名没有像
这样的空格,这将起作用
Filename.cpp
New.cpp
example.cpp
nospace.cpp
但是如果我使用空格...
Hello World.cpp
This has a space.cpp
New error.cpp
它会产生以下错误:
NPP_SAVE: D:\C++\My Projects\New text.cpp
CD: D:\C++\My Projects
Current directory: D:\C++\My Projects
g++ "New text.cpp" -o New text -march=native -O3
Process started (PID=13652) >>>
g++: error: text: No such file or directory
<<< Process finished (PID=13652). (Exit code 1)
NPP_RUN: New text
; executing: NPP_RUN New text
- the specified file was not found
================ READY ================
之前你说是因为我的代码有错,其实不是,那是我遇到问题的同一个文件,代码是复制粘贴的....我将文件命名为Test File.cpp
并得到错误,但在更改为 TestFile.cpp
后,它没有显示上述错误,而且代码没有被编辑
为什么以及如何避免这种情况?
显而易见的答案是不要在文件名中使用空格。就是问问题。
但在这种情况下,您是否尝试过在 NAME_PART 变量周围使用 "
?
g++ "$(FILE_NAME)" -o "$(NAME_PART)" -march=native -O3
NPP_RUN "$(NAME_PART)"
我认为 ...-o New text
是问题所在。这应该编译:
g++ "New text.cpp" -o 'New text' -march=native -O3
所以我用notepad++的NppExec直接编译执行C++文件
npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)
一切正常,现在假设我有这段代码:
#include <iostream>
using namespace std;
int main() {
cout << "This is a normal statement" << endl;
cout << "This statement uses endl;" << endl;
cout << "This one has " << "multiple " << "chevrons" << "Cant tell huh?" << endl;
cout << "This is a flush statement, this does not break line like this :" << flush;
cout << "Me flush statement" << endl;
system("pause");
return 0;
}
我是用上面的执行代码编译的.....
好吧,如果文件名没有像
这样的空格,这将起作用Filename.cpp
New.cpp
example.cpp
nospace.cpp
但是如果我使用空格...
Hello World.cpp
This has a space.cpp
New error.cpp
它会产生以下错误:
NPP_SAVE: D:\C++\My Projects\New text.cpp
CD: D:\C++\My Projects
Current directory: D:\C++\My Projects
g++ "New text.cpp" -o New text -march=native -O3
Process started (PID=13652) >>>
g++: error: text: No such file or directory
<<< Process finished (PID=13652). (Exit code 1)
NPP_RUN: New text
; executing: NPP_RUN New text
- the specified file was not found
================ READY ================
之前你说是因为我的代码有错,其实不是,那是我遇到问题的同一个文件,代码是复制粘贴的....我将文件命名为Test File.cpp
并得到错误,但在更改为 TestFile.cpp
后,它没有显示上述错误,而且代码没有被编辑
为什么以及如何避免这种情况?
显而易见的答案是不要在文件名中使用空格。就是问问题。
但在这种情况下,您是否尝试过在 NAME_PART 变量周围使用 "
?
g++ "$(FILE_NAME)" -o "$(NAME_PART)" -march=native -O3
NPP_RUN "$(NAME_PART)"
我认为 ...-o New text
是问题所在。这应该编译:
g++ "New text.cpp" -o 'New text' -march=native -O3