Adding -std=gnu++11 compiler flag to QMake

一个人想着一个人 提交于 2019-12-10 17:26:58

问题


I am compiling qt5.7 on windows with mingw32 and g++.4.9.3. While executing the configure.bat, I get this error :

C:\qt-everywhere-opensource-src-5.7.0\configure.bat -prefix C:\Qt-5.7 -skip qttools -skip qtwebchannel -skip qtwebengine -skip qtcharts -skip qtdatavis3d -platform win32-g++

C:\qt-everywhere-opensource-src-5.7.0\qtbase/qmake/library/qmakebuiltins.cpp: In member function 'QByteArray QMakeEvaluator::getCommandOutput(const QString&) const': C:\qt-everywhere-opensource-src-5.7.0\qtbase/qmake/library/qmakebuiltins.cpp:419:94: error: '_popen' was not declared in this scope + QLatin1String(" && ") + args).toLocal8Bit().constData(), "r")) {

The command that leads to this error is :

g++ -c -o qmakebuiltins.o -std=c++11 -DUNICODE -ffunction-sections -g -IC:\qt-everywhere-opensource-src-5.7.0\qtbase/qmake + lot of stuff

Also, the following code :

    #include <stdio.h>

int main( int argc, char ** argv )
{
     FILE * f = popen( argv[ 1 ], "r" );
     return 0;
}

doesn't compile with

g++ -std=c++11 mytest.cpp -o mytest

but with :

>g++ -std=gnu++11 mytest.cpp -o mytest

So the question is how can I modify the option c++11 to gnu++11 which is passed to g++ by the configure file ? Thank you


回答1:


Adding compiler options is quite easy in Qt. Just add the following lines some where in your qmake file.

# C++ Compiler flags: Gnu C++ Extensions
QMAKE_CXXFLAGS += -std=gnu++11

Similarly if you want to pass C compiler options, use this

# C Compiler flags for qmake 
QMAKE_CFLAGS += -std=gnu99

The reason _popen does not work with c++11 is that its implemented as a GNU C++ Extension and is not in standard C++. Similarly, VisualStudio too defines _popen separately from the C++ standard library.




回答2:


According to Qt's Wiki, with the current version of qmake you are using, you can also use CONFIG += c++11.




回答3:


I found a workaround by downloading another version of mingw on the download repository of qt : here



来源:https://stackoverflow.com/questions/38433140/adding-std-gnu11-compiler-flag-to-qmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!