我是 Qt 和 C++ 的新手,我想创建一个简单的项目。我写了这段代码:
#include <QString>
int main()
{
QString str = "a,,b,c";
return 0;
}
我像这样编译它:
g++ -o LeapMouse Leapmouse.cpp -I /home/dougui/Qt/5.1.1/gcc_64/include/QtCore -I /home/dougui/Qt/5.1.1/gcc_64/include -fPIE
我有这个错误:
/tmp/cc6umRmY.o: In function `QString::QString(char const*)':
Leapmouse.cpp:(.text._ZN7QStringC2EPKc[_ZN7QStringC5EPKc]+0x34): undefined reference to `QString::fromAscii_helper(char const*, int)'
/tmp/cc6umRmY.o: In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
Leapmouse.cpp: (.text._ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1e): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status
当我这样做时grep -ri 'fromAscii_helper' /home/dougui/Qt/5.1.1/gcc_64/include
,您可以在此处看到该功能:
/home/dougui/Qt/5.1.1/gcc_64/include/QtCore/qstring.h: static Data *fromAscii_helper(const char *str, int size = -1);
它应该包括在内。我错过了什么吗?是否可以将 Qt 的库包含到标准 C++ 项目中?