Katherine1
Katherine1

Reputation: 195

Qt Creator undefined reference to existing class

I'm writing an application that uses another library that I'm developing at the same time. This creates the problem where QtCreator will be expecting the library to never change to the point where removed headers cause building the project to fail, and new classes are reported as undefined even if they compile into the library just fine. What is with this? It's like it's not actually looking at the library. Is there any way I can force it to let me use the newer additions to my library?

Here is the Application .pro

QT       += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = BlockEditor
TEMPLATE = app


SOURCES += main.cpp\
    mainwindow.cpp \
    openglqt.cpp \
    tilelabel.cpp

HEADERS  += mainwindow.h \
    openglqt.h \
    tilelabel.h

FORMS    += mainwindow.ui

LIBS += -L/usr/local/lib -lGLU -lGLEW

QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/libs
QMAKE_RPATH=

release {
    LIBS += -L$$PWD/../drEngine/bin/Release/ -ldrEngine
}
debug {
    LIBS += -L$$PWD/../drEngine/bin/Debug/ -ldrEngine
}

INCLUDEPATH += $$PWD/../drEngine
DEPENDPATH += $$PWD/../drEngine

QMAKE_CXXFLAGS += -std=c++11

The Library is developed over in Code::Blocks

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
    <FileVersion major="1" minor="6" />
    <Project>
        <Option title="Dark Realms Engine" />
        <Option pch_mode="2" />
        <Option compiler="gcc" />
        <Build>
            <Target title="Debug">
                <Option output="bin/Debug/drEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
                <Option object_output="obj/Debug/" />
                <Option type="3" />
                <Option compiler="gcc" />
                <Option createDefFile="1" />
                <Option createStaticLib="1" />
                <Compiler>
                    <Add option="-g" />
                </Compiler>
            </Target>
            <Target title="Release">
                <Option output="bin/Release/drEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
                <Option object_output="obj/Release/" />
                <Option type="3" />
                <Option compiler="gcc" />
                <Option createDefFile="1" />
                <Option createStaticLib="1" />
                <Compiler>
                    <Add option="-O3" />
                </Compiler>
                <Linker>
                    <Add option="-s" />
                </Linker>
            </Target>
        </Build>
        <Compiler>
            <Add option="-std=c++11" />
            <Add option="-Wall" />
        </Compiler>
        <Unit filename="Block.cpp" />
        <Unit filename="Block.hpp" />
        <Unit filename="BlockList.cpp" />
        <Unit filename="BlockList.hpp" />
        <Unit filename="Camera2D.cpp" />
        <Unit filename="Camera2D.hpp" />
        <Unit filename="Camera3D.cpp" />
        <Unit filename="Camera3D.hpp" />
        <Unit filename="Entity.hpp" />
        <Unit filename="Includes.hpp" />
        <Unit filename="RenderInfo.cpp" />
        <Unit filename="RenderInfo.hpp" />
        <Unit filename="Renderer.cpp" />
        <Unit filename="Renderer.hpp" />
        <Unit filename="Scene.cpp" />
        <Unit filename="Scene.hpp" />
        <Unit filename="TextureAtlas.cpp" />
        <Unit filename="TextureAtlas.hpp" />
        <Unit filename="dr.hpp" />
        <Unit filename="isoMap.cpp" />
        <Unit filename="isoMap.hpp" />
        <Extensions>
            <envvars />
            <code_completion />
            <lib_finder disable_auto="1" />
            <debugger />
            <DoxyBlocks>
                <comment_style block="0" line="0" />
                <doxyfile_project />
                <doxyfile_build />
                <doxyfile_warnings />
                <doxyfile_output />
                <doxyfile_dot />
                <general />
            </DoxyBlocks>
        </Extensions>
    </Project>
</CodeBlocks_project_file>

Upvotes: 1

Views: 2458

Answers (1)

j_kubik
j_kubik

Reputation: 6181

I know the pains of developing library and app using it.

Are you sure that you recompile both on updates? - normally qt creator updates only current project. If you go to 'Project' screen and 'Dependencies' tab, you can tell QtCreator that one project depends on another - should be always kept in sync.

Also avoid copying of the final library to application folder if library is still under development. Best way is to symlink library from it's original position to your application directory. Even newer versions of windows offer symlinks these days (never tried it myself though), so you should have no trouble to do it this way.

If this doesn't help, mor edetailed analysys is required, so please post your qmake .pro files for both application and library.

EDIT:

BTW "QtCreator will be expecting the library to never change" - Qt Creator doesn't care about your library at all - this is handled at the level of qmake (which doesn't care about it's contents as well, it only knows what is written in .pro file), and later linker.

Easiest to try would be to remove EVERYTHING not user created from both projects - so sources and your .pro files and whatever equivalent Code::Block uses are the only thing to stay. Then compile both as if you just written them now. If it still doesn't work, it means that it's not QtCreator (or qmake, or linker) problem but problem with your source.

If this doesn't work, then I suspect you have some stale version of your library somewhere in your build environment. It seems that you use linux and ld as compiler (right?). Try using --trace option to see which version of your library is being used. Just add

LIBS += -Xlinker --trace

To your .pro file, and see compiler output.

Upvotes: 1

Related Questions