I have two projects using Qt. One is being developed with QtCreator, the other with eclipse. Both use the same Qt 5.3.1 libraries, both compiled using GCC. However, when I run an eclipse program, it crashes with the Undefined symbol: _ZN7QString13toUtf8_helperERKS_ message Undefined symbol: _ZN7QString13toUtf8_helperERKS_ .
The search showed that the code generating this error,
path.toStdString().c_str()
and exact location in qstring.h
#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) QByteArray toLatin1() const & Q_REQUIRED_RESULT { return toLatin1_helper(*this); } QByteArray toLatin1() && Q_REQUIRED_RESULT { return toLatin1_helper_inplace(*this); } QByteArray toUtf8() const & Q_REQUIRED_RESULT { return toUtf8_helper(*this); } // <- here QByteArray toUtf8() && Q_REQUIRED_RESULT { return toUtf8_helper(*this); } QByteArray toLocal8Bit() const & Q_REQUIRED_RESULT { return toLocal8Bit_helper(constData(), size()); } QByteArray toLocal8Bit() && Q_REQUIRED_RESULT { return toLocal8Bit_helper(constData(), size()); }
Converting a QString to std::string to another project (the one in QtCreator) works fine. What could be the problem? Are there any compiler options in eclipse?
Edit: Compiler output for sample files from two projects (I added line breaks for readability):
Eclipse
Building file: ../src/mysource1.cpp Invoking: GCC C++ Compiler g++ -I"/home/username/myfolder/myproject1/src" -I"/home/username/myfolder/myproject1/src/dialogs" -I"/home/username/myfolder/myproject1/src/ignore" -I/usr/local/Qt-5.3.1/include -I/usr/local/Qt-5.3.1/include/QtCore -I/usr/local/Qt-5.3.1/include/QtGui -I/usr/local/Qt-5.3.1/include/QtWidgets -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -fPIE -MMD -MP -MF"src/mysource1.d" -MT"src/mysource1.d" -o "src/mysource1.o" "../src/mysource1.cpp"
QtCreator
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/local/Qt-5.3.1/mkspecs/linux-g++ -I../myproject2 -I../myproject2/src -I../myproject2/src/data -I../myproject2/src/dialogs -I../myproject2/src/widgets -I../myproject2/src/widgets/overlays -I../myproject2/src/widgets/tools -I/usr/local/Qt-5.3.1/include -I/usr/local/Qt-5.3.1/include/QtWidgets -I/usr/local/Qt-5.3.1/include/QtGui -I/usr/local/Qt-5.3.1/include/QtCore -I. -I. -o mainwind.o ../myproject2/src/mainwind.cpp
Edit2: The linker outputs are as follows:
Eclipse
Invoking: GCC C++ Linker g++ -L/usr/local/Qt-5.3.1/lib -o "myproject1" /*list of .o files*/ -lQt5Core -lQt5Gui -lQt5Widgets -lgit2
QtCreator
g++ -Wl,-rpath,/usr/local/Qt-5.3.1/lib -o myproject2 /*list of .o files*/ -L/usr/local/Qt-5.3.1/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread