Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Linker error with testlib project



  • Hello,

    I have been using Qt Creator as a Qt and general purpose IDE for the past few weeks. My desktop and Wt applications are running fine. I am now in the process of creating a core library project with associated unit test suite (my first attempt at using the testlib framework). I created the project based upon http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html.

    @
    QT += testlib
    QT -= gui

    CONFIG += console
    CONFIG -= app_bundle

    TARGET = UnitTest
    TEMPLATE = app

    INCLUDEPATH +=
    /opt/local/include
    /opt/local/include/mongo
    src test

    LIBS +=
    -lssl -lcrypto

    SOURCES +=
    src/util/Encrypter.cpp
    test/main.cpp
    test/util/EncrypterTestSuite.cpp

    HEADERS +=
    src/util/Encrypter.h
    test/AutoTest.h
    test/util/EncrypterTestSuite.h
    @

    The code builds fine, however linking fails with the following error:

    @g++ -headerpad_max_install_names -o UnitTest Encrypter.o main.o EncrypterTestSuite.o moc_EncrypterTestSuite.o -F/Library/Frameworks -L/Library/Frameworks -lssl -lcrypto -framework QtTest -L/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib -F/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib -framework IOKit -framework ApplicationServices -framework Security -framework QtCore
    ld: warning: directory not found for option '-L/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib'
    ld: warning: directory not found for option '-F/tmp/qt-stuff-6474/source/qt-everywhere-opensource-src-4.7.0/lib'
    Undefined symbols for architecture x86_64:
    "EncrypterTestSuite::initTestCase()", referenced from:
    EncrypterTestSuite::qt_metacall(QMetaObject::Call, int, void**)in moc_EncrypterTestSuite.o
    "EncrypterTestSuite::testAes()", referenced from:
    EncrypterTestSuite::qt_metacall(QMetaObject::Call, int, void**)in moc_EncrypterTestSuite.o
    "EncrypterTestSuite::testDes()", referenced from:
    EncrypterTestSuite::qt_metacall(QMetaObject::Call, int, void**)in moc_EncrypterTestSuite.o
    "EncrypterTestSuite::cleanupTestCase()", referenced from:
    EncrypterTestSuite::qt_metacall(QMetaObject::Call, int, void**)in moc_EncrypterTestSuite.o
    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    make: *** [UnitTest] Error 1
    make: Leaving directory `/Users/rakesh/svn/cpp/coretest-build-desktop'
    The process "/usr/bin/make" exited with code %2.
    Error while building project coretest (target: Desktop)
    When executing build step 'Make'@

    The build directory contains all the .o files, so I am not sure what is wrong. Just running the test project downloaded from above mentioned link does work fine. Any idea what I might be missing in my project configuration?

    Thanks in advance for all help.
    Rakesh



  • Never mind, classic case of me spotting the problem a few seconds after posting the issue. Auto complete seems to have messed up the class name in the test class implementation file. Sorry for wasting bandwidth.


Log in to reply