Why is Qt reporting > 14000 errors in this one page source file?
Here is the code:
#include <QtCore/QCoreApplication>
#include <QProcess>
#include <QProcessEnvironment>
int main(int argc, char *argv[])
{
QProcessEnvironment env;
// Environment variables required by CGI apps
env.insert("QUERY_STRING", url.encodedQuery());
env.insert("REQUEST_URI", url.toString());
env.insert("REQUEST_METHOD", "GET");
env.insert("REMOTE_ADDR", pSocket->peerAddress().toString());
//==========
QProcess process;
process.setProcessEnvironment(env);
process.start("php-cgi",QProcess::ReadWrite);
process.write("<?php print_r($_GET); ?>");
process.closeWriteChannel();
process.waitForFinished();
qDebug(process.readAll().data());
return 0;
}
Qt Creator reports more than 14000 errors. Here is a small sample of them:
In file included from ../QProcess/main.cpp:2: ../QProcess/QProcess:1: error: stray ‘\17开发者_开发问答7’ in program ../QProcess/QProcess:1: error: stray ‘\2’ in program ../QProcess/QProcess:1: error: stray ‘\1’ in program ../QProcess/QProcess:1: error: stray ‘\1’ in program In file included from ../QProcess/main.cpp:2: ../QProcess/QProcess:1:8: warning: null character(s) ignored ../QProcess/QProcess:1: error: stray ‘\2’ in program
Here is a simple example instance of this error. The contents of a file called new.cpp:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Brand new." << std::endl;
return 0;
}
Now compile it:
ppu32-g++ new.cpp -o new
No problem. Let's compile it again:
ppu32-g++ new.cpp -o new
OMG! Screen after screen of errors! Most of these errors look like this:
./new:1: error: stray '\177' in program
The problem is that the compiler is trying to use the new file in the current directory, as the C++ standard library <new>
; used by <iostream>
. In fact any file in the current directory, named after a C++ standard library header, which is used in the code being compiled, will likely cause an error. That our problem file is an executable obfuscates the error messages.
It doesn't occur on all the gcc machines I've tried. ppu32-g++
4.1.1 on PS3 Cell Fedora Linux certainly chokes.
If that problem arises not on every host then probably difference in the compiler. Difference is likely in the header files directory scan order. Such error should not arise if standard headers directory scanned before others.
As a workaround its enough to remove project target file manually befor building target. But this is not a programmers way (which are very lazy creatures).
Programmers way - is to learn QMake to delete target file just before project sources compilations (but under this way link phase will be done permanently). For me (QMake 2.01a under Linux) this is achived by addition of following lines into project file:
deltarget.commands = $$QMAKE_DEL_FILE $$TARGET
QMAKE_EXTRA_TARGETS += deltarget
PRE_TARGETDEPS += deltarget
This declares target deltarget which becomes built before current project. This sample uses undeclared in QMake's manual variable QMAKE_DEL_FILE which used to remove files (its content of course platfrom-dependent).
精彩评论