Menu

Link error: undefined reference to `PythonQt::init(int, QByteArray const&)'

Help
David Lyon
2017-04-28
2017-04-28
  • David Lyon

    David Lyon - 2017-04-28

    I downloaded PythonQt3.1 and opened src.pro with QtCreator4.2.2 (QT 5.8.0), everything complied and linked fine under Ubuntu 16.04 (after commenting out the two hint buttons), I ended up with eight *.so files:
    libPythonQt.so - 20 bytes
    libPythonQt.so.1 - 20 bytes
    libPythonQt.so.1.0 - 20 bytes
    libPythonQt.so.1.0.0 - 3.4 MBytes
    and their debug counterparts in /home/user/Downloads/PythonQt3.1/lib/

    I created a simple program in QtCreator to test in /home/user/CppCode/StocksWeb/ with this pro file:

    QT       += core gui sql widgets
    INCLUDEPATH += "/home/user/Downloads/PythonQt3.1/src"
    INCLUDEPATH += "/usr/include/python2.7"
    Debug:LIBS += -L"/home/user/Downloads/PythonQt3.1/lib" -libPythonQt_d.so
    Release:LIBS += -L"/home/user/Downloads/PythonQt3.1/lib" -libPythonQt.so
    DEFINES += QT_DEPRECATED_WARNINGS
    SOURCES += src/main.cpp src/mainwindow.cpp
    HEADERS  += src/mainwindow.h
    FORMS    += src/mainwindow.ui
    

    And this main code (after reducing it greatly):

    #include "mainwindow.h"
    #include <QApplication>
    #include <PythonQt.h>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    // Tried both
    //    PythonQt::init(1, QByteArray("PythonQt"));
        PythonQt::init();
    
        return a.exec();
    }
    

    The two cpp and ui files compile fine, however when linking I get this output in QtCreater:

    main.o: In function `main':
    /home/user/CppCode/StocksWeb/64debug/../src/main.cpp:11: undefined reference to `PythonQt::init(int, QByteArray const&)'
    Makefile:237: recipe for target 'StocksWeb' failed
    collect2: error: ld returned 1 exit status
    make: *** [StocksWeb] Error 1
    20:32:03: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project StocksWeb (kit: Desktop Qt 5.8.0 GCC 64bit)
    When executing step "Make"
    20:32:03: Elapsed time: 00:05.
    

    After making no progress after serveral hours I decided to ask for help. Any hints or ideas would be greatly appreciated. Thanks!

                                            RESOLVED
    

    I resolved it, I had to change the way the project file add paths to the libraries:

    CONFIG(debug, debug|release): LIBS += -L$$PWD/../3rdParty/lib/ -lPythonQt_d
    else: LIBS += -L$$PWD/../3rdParty/lib/ -lPythonQt

    My normal path to 3rd party stuff is /home/user/CppCode/3rdParty/. Now everything appears to be right with the libraries and include files in the right place.

    Just a reminder, once you have your libraries in a permenant place don't forget to run ldconfig to register them with the operating system.

     

    Last edit: David Lyon 2017-04-28
  • hanzongjin

    hanzongjin - 2017-05-10

    excuse me,I just want to know where you found PythonQt_d.lib. I haven't found it in the pythonQt3.1 zip package.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.