[Solved] Clang on Pi returns undefined reference to `operator new(unsigned long)'
-
Hi. I am stuck trying to link programs using clang. All is fine with gcc, but when I use either of these with the current Raspbian
QT5
@qmake -makefile -spec linux-clang
@Or QT4
@qmake -makefile -spec unsupported/linux-clang
@At link time this happens:
main.o: In function
main': main.cpp:(.text+0x2c): undefined reference to
operator new(unsigned long)'
main.cpp:(.text+0xa0): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [clang_test2] Error 1It happens even with the simplest of programs, for example this:
main.cpp
@#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QPushButton *b = new QPushButton ("Hello world !");
QObject::connect(b,SIGNAL(pressed()),&app,SLOT(closeAllWindows()));
b->show();
app.exec();
delete b;
}@simple_test.pro
@TEMPLATE = app
TARGET = clang_test2
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp@Anyone any ideas?
-
linux-clang is a mkspec written for x86 architecture. You need to modify the linux-rasp-pi-g++ to use clang, then it should work.
-
Cool, thank you! I didn't realise clang could interpret so many of gcc's options and switches. I literally replaced g++ with clang and it ran!
Being curious I took the compile and link commands make generated and deleted the options one at a time until it broke as before. The simplest working compile and link is
@clang -c -mabi=aapcs-linux -fPIE -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -o main.o main.cpp
clang -o clang_test2 main.o -lQt5Widgets -lstdc++@and if you drop the -mabi=aapcs-linux option on the compiler you get the error about the missing new operator.
-
Good inqusitiveness :-) I'm glad it helped you. Happy coding