简体   繁体   English

使用QProcess的G ++ makefile命令

[英]G++ makefile command with QProcess

I'm trying to generate a .exe file with g++ compiler. 我正在尝试使用g ++编译器生成.exe文件。 I tried multiple ways without sucess. 我尝试了多种方法而没有成功。

1) QString program = "C:/Strawberry/c/bin/g++";
QStringList arguments;
arguments << "g++ -o dialog C:/Documents/ED30/dialog.cpp";
QProcess process;
process.start(program, arguments);
process.waitForFinished(-1);

2) QProcess::execute("g++ -o dialog2 C:/Documents/ED30/dialog.cpp");

3) QProcess::execute("g++ C:/Documents/ED30/dialog.cpp -o dialog2"); 

Everytime I have the same error message : 每当我有相同的错误消息:

"In file included from C:/Documents/ED30/dialog.cpp:1:0: C:/Documents/ED30/dialog.h:4:19: fatal error: QDialog: No such file or directory compilation terminated." “在C:/Documents/ED30/dialog.cpp:1:0中包含的文件中:C:/Documents/ED30/dialog.h:4:19:致命错误:QDialog:没有这样的文件或目录编译终止。”

Or sometimes nothing happens. 或有时什么也没有发生。

I'm using Qt 5.7 with MinGW on windows 8.1 我在Windows 8.1上将Qt 5.7与MinGW一起使用

EDIT: So after discussing the issue with members, I did some progress. 编辑:因此,在与成员讨论了该问题之后,我取得了一些进展。 Best code until now is : 到目前为止最好的代码是:

system("g++ -o dialog2 -I C:/Qt/5.8/mingw53_32/include -I C:/Qt/5.8/mingw53_32/include/QtGui -I C:/Qt/5.8/mingw53_32/include/QtCore -I C:/Qt/5.8/mingw53_32/include/QtWidgets -L C:/Qt/5.8/mingw53_32/lib C:/Documents/ED30/dialog.cpp");

But this indicats me that MinGW isn't a c++ 11 compiler and it suggests me to write "-std=c++11 or -std=gnu++11" in the command-line in order to update the Compiler. 但这表明我MinGW不是c ++ 11编译器,建议我在命令行中写“ -std = c ++ 11或-std = gnu ++ 11”以更新编译器。 After typing it in the compiler, the following error appears: "Unknow command". 在编译器中键入它后,将出现以下错误:“未知命令”。 I tried with Qt 5.7 and 5.8 without success. 我尝试使用Qt 5.7和5.8失败。 A solution guys ? 解决方案的家伙?

It seems the code you are trying to compile dialog.cpp makes use of Qt (QDialog in particular). 似乎您尝试编译dialog.cpp的代码使用了Qt(特别是QDialog)。

When you run g++ -o dialog2 C:/Documents/ED30/dialog.cpp , g++ fails because it cannot find where Qt header and library files are. 当您运行g++ -o dialog2 C:/Documents/ED30/dialog.cpp ,g ++会失败,因为它找不到Qt标头和库文件所在的位置。

The minimal command line to make it work would be: 使它起作用的最小命令行为:

g++ -o dialog2 -I<PathToQtheaders> -L<PathToQtLibraries> -lQt5Core -lQt5Gui -lQt5Widgets C:/Documents/ED30/dialog.cpp

You might need to add some extra libraries depending on what you code needs. 您可能需要根据代码需求添加一些额外的库。 Note that you cannot use Q_OBJECT macro if you just compile it like that (without calling moc etc.). 请注意,如果只是像这样编译它(不调用moc等),则不能使用Q_OBJECT宏。

Tip: Look at the commands generated by qmake on a standard Qt project. 提示:查看标准Qt项目上qmake生成的命令。

Extra tip: You can use QLibraryInfo::location() to get Qt installation paths. 额外提示:您可以使用QLibraryInfo::location()获取Qt安装路径。

Also your first example should be: 同样,您的第一个示例应该是:

QString program = "C:/Strawberry/c/bin/g++";
QStringList arguments;
arguments << "-o" << "dialog" << "C:/Documents/ED30/dialog.cpp";
QProcess process = "g++";
process.start(program, arguments);
process.waitForFinished(-1);

I think you are missing the include directory of your Qt headers. 我认为您缺少Qt标头的包含目录。

QProcess::execute("g++ -o dialog -IC:\\QtDir C:/Documents/ED30/dialog.cpp"); QProcess :: execute(“ g ++ -o对话框-IC:\\ QtDir C:/Documents/ED30/dialog.cpp”);

QtDir is the actual location of the Qt Headers on your system like C:\\Qt\\include QtDir是系统上Qt标头的实际位置,例如C:\\ Qt \\ include

You may also have trouble linking. 您可能也无法连接。 The whole command is: 整个命令是:

QProcess::execute("g++ -o dialog -IC:\\QtDir\\include -LC:\\Qtdir\\lib -l Qt C:/Documents/ED30/dialog.cpp") QProcess :: execute(“ g ++ -o对话框-IC:\\ QtDir \\ include -LC:\\ Qtdir \\ lib -l Qt C:/Documents/ED30/dialog.cpp”)

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

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