Another static library issue. [solved]



  • I followed this guide for creating and using a static library in Qt:
    https://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application

    I have a class that I would like to use in Matlab, so I would like to create a static library. I am using Qt 4.8.0, statically compiled, commercial on a Windows 7 machine.

    I created a project for the library:
    @
    QT += network
    TEMPLATE = lib
    CONFIG+= staticlib

    Input

    INCLUDEPATH += ../common/output
    ../common/input
    ../common/core
    ../common/crc

    HEADERS += ../common/output/imageUdpSender.h
    ../common/input/image.h
    ../common/core/coreModule.h
    ../common/input/internalProtocol.h
    ../common/output/testState.h
    ../common/crc/crc.h

    SOURCES += ../common/output/imageUdpSender.cpp
    ../common/core/coreModule.cpp
    ../common/output/testState.cpp
    ../common/crc/crc.cpp

    INTF_VERSION = 2
    INTF_VERSTR = '\"$${INTF_VERSION}\"'
    DEFINES += INTERFACE_VERSION="$${INTF_VERSTR}"

    TARGET = ../../../ShutterSoftware/build/Library

    static { # everything below takes effect with CONFIG += static
    TARGET = ../../../../../ShutterSoftware/build/static/Library
    CONFIG += static
    QTPLUGIN += qsvg qico #qpng # image formats
    DEFINES += STATIC
    message("~~~ static build ~~~") # this is for information, that the static build is done
    mac: TARGET = $$join(TARGET,,static,_static) #this adds an _static in the end, so you can seperate static build from non static build
    win32: TARGET = $$join(TARGET,,static,s) #this adds an s in the end, so you can seperate static build from non static build
    }
    @

    The above project creates a *.lib. However, when I tried to include it in a project, I get this error:

    @C:\Users\IKOMED6\Documents\SVN\Software\ShutterControlGUI\Qt\ShutterSoftware\ShutterUILibrary\TestLibrary\main.cpp:2: error: C1083: Cannot open include file: 'imageUdpSender.h': No such file or directory@

    The project file for the project trying to use the library:

    @QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = TestLibrary
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    INCLUDEPATH += $$PWD/../../build/static
    LIBS += -static -L$$PWD/../../build/static/ -lLibrarys.lib

    TARGET = ../../../ShutterSoftware/build/TestLibrary

    static { # everything below takes effect with CONFIG += static
    TARGET = ../../../../../ShutterSoftware/build/static/TestLibrary
    CONFIG += static
    QTPLUGIN += qsvg qico #qpng # image formats
    DEFINES += STATIC
    message("~~~ static build ~~~") # this is for information, that the static build is done
    mac: TARGET = $$join(TARGET,,static,_static) #this adds an _static in the end, so you can seperate static build from non static build
    win32: TARGET = $$join(TARGET,,static,s) #this adds an s in the end, so you can seperate static build from non static build
    }
    @

    and the main.cpp is extremely simple (I only made this project to test the .lib):

    @#include "mainwindow.h"
    #include "imageUdpSender.h"

    int main(int argc, char *argv[])
    {

    }@

    I'm not sure what is wrong... how do I even know if the *.lib was created properly? I've tried everything I've found online, so I'm at a loss...

    Thanks in advance.


  • Lifetime Qt Champion

    Hi,

    Currently, you're not even linking to your library, what you have is an INCLUDEPATH problem. Where is "imageUdpSender.h" located ?



  • Thanks for your speedy reply! The imageUdpSender.h is located in common/output, which I have in the include path: ../common/output

    Now, I originally thought this was the issue, but when I comment out image.h (which is included in imageUdpSender.h), the Library project will not compile and states it is missing image.h. To me, this indicated that I am linking to the library in Library.pro, but I guess I'm wrong.

    Here is the folder structure, I hope this makes sense.

    Project Folder
    -common
    --input
    --output
    --core
    --crc
    -build
    --static
    ---Librarys.lib # not a typo
    -Library (Project to create static library)
    --library.pro (ie. first .pro above)
    -TestLibrary (Project to test above static library)
    --Test.pro (ie. second .pro above)
    --main.cpp (above)



  • I had a fundamental misunderstanding about static libraries. I think I have it cleared up now, thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.