Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. [Solved] Clang on Pi returns undefined reference to `operator new(unsigned long)'
Forum Updated to NodeBB v4.3 + New Features

[Solved] Clang on Pi returns undefined reference to `operator new(unsigned long)'

Scheduled Pinned Locked Moved QtonPi
4 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Batteries Included
    wrote on 3 Jul 2014, 19:58 last edited by
    #1

    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 1

    It 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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 4 Jul 2014, 05:29 last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Batteries Included
        wrote on 4 Jul 2014, 07:13 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 4 Jul 2014, 10:11 last edited by
          #4

          Good inqusitiveness :-) I'm glad it helped you. Happy coding

          (Z(:^

          1 Reply Last reply
          0

          1/4

          3 Jul 2014, 19:58

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved