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

static library. no such file or directory



  • I am trying to follow qt creators instructions to create static libraries.
    https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

    it shows the below for lines to include in my libraries .pro

    TEMPLATE = lib
    CONFIG += staticlib
    
    # Input
    HEADERS += test.h
    SOURCES += test.cpp
    

    and for the apps .pro

    TEMPLATE = app
    TARGET =
    CONFIG += console
    
    # Input
    SOURCES += main.cpp
    INCLUDEPATH += ../staticLibrary
    LIBS += -L../staticLibrary/debug -lstaticLibrary
    

    I have

    library test.pro

    QT       -= gui
    
    TARGET = Test
    TEMPLATE = lib
    CONFIG += staticlib
    
    SOURCES += test.cpp
    
    HEADERS += test.h
    unix {
        target.path = /usr/lib
        INSTALLS += target 
    }
    

    app.pro
    QT += core
    QT -= gui

    CONFIG += c++11

    TARGET = App
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += ../test
    LIBS += -L../test/debug -ltest
    message("INCLUDEPATH " $$INCLUDEPATH)
    message("LIBS " $$LIBS)

    My library is test. Both folder, the main app and the library are in the same folder. When I now include the .h

    #include "test.h"
    

    I get

    C:\CPP\Test\App\main.cpp:3: error: C1083: Cannot open include file: 'test.h': No such file or directory


  • Do a run qmake in creator and try again.



  • No change. I am not sure what qmake does. when I run it, there is no prompt or pop up saying it does something



  • Did you run qmake from creator?
    This is accomplished through "Build"->"Run qmake". There should be a small bar showing in the lower right corner of Qt creator. The bar turns to green when qmake has finished.
    In the "Compile Output" window you may see at least that it has been started and finished.
    If you have placed message statements in your .pro file the output of those messages may be seen there too.

    For your checking you can check the content of INCLUDEPATH for example.

    TEMPLATE = app
    TARGET =
    CONFIG += console
    
    # Input
    SOURCES += main.cpp
    INCLUDEPATH += ../staticLibrary
    LIBS += -L../staticLibrary/debug -lstaticLibrary
    message("INCLUDEPATH " $$INCLUDEPATH)
    message("LIBS " $$LIBS)
    

    Concerning your problem: do you have the file "c:\CPP\Test\Test\test.h" ?
    That is where you are looking for "test.h".



  • yes, I ran it from the build menu.

    my path is C:\CPP\Test\Test and the test.h is in there

    Below is the output when I run qmake and then run App. Now it says cannot find test.lib
    13:18:45: Running steps for project App...
    13:18:45: Starting: "C:\Qt\5.7\msvc2015_64\bin\qmake.exe" C:\CPP\Test\App\App.pro -spec win32-msvc2015 "CONFIG+=debug" "CONFIG+=qml_debug"
    Project MESSAGE: INCLUDEPATH ../test
    Project MESSAGE: LIBS -L../test/debug -ltest
    Project MESSAGE: INCLUDEPATH ../test
    Project MESSAGE: LIBS -L../test/debug -ltest
    Project MESSAGE: INCLUDEPATH ../test
    Project MESSAGE: LIBS -L../test/debug -ltest
    13:18:45: The process "C:\Qt\5.7\msvc2015_64\bin\qmake.exe" exited normally.
    13:18:45: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe" qmake_all

    jom 1.1.0 - empower your cores

    13:18:45: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited normally.
    13:18:45: Elapsed time: 00:00.

    after run

    13:20:02: Running steps for project App...
    13:20:02: Configuration unchanged, skipping qmake step.
    13:20:02: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe"
    C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
    link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='' processorArchitecture=''" /MANIFEST:embed /OUT:debug\App.exe @C:\Users\CE\AppData\Local\Temp\App.exe.11204.16.jom
    LINK : fatal error LNK1104: cannot open file 'test.lib'
    jom: C:\CPP\Test\build-App-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\Makefile.Debug [debug\App.exe] Error 1104
    jom: C:\CPP\Test\build-App-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\Makefile [debug] Error 2
    13:20:02: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
    Error while building/deploying project App (kit: Desktop Qt 5.7.0 MSVC2015_64bit)
    When executing step "Make"
    13:20:02: Elapsed time: 00:00.

    I do have a Test.lib in
    C:\CPP\Test\build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\debug


  • Qt Champions 2017

    @zicx said in static library. no such file or directory:

    LINK : fatal error LNK1104: cannot open file 'test.lib'

    Is different from

    C:\CPP\Test\App\main.cpp:3: error: C1083: Cannot open include file: 'test.h': No such file or directory

    So why do you say there's no change?
    Anyway, output your project's current directory:

    message("pwd: " $$PWD)
    

    and make sure the library is generated at the specified location - that is when you apply the relative path you've passed to the LIBS variable to the current directory (PWD). Also do give your target a name:

    TARGET = myapplication
    


  • I missed that change in error, initially

    So, I get this
    Project MESSAGE: pwd: C:/CPP/Test/App
    Project MESSAGE: INCLUDEPATH ../test
    Project MESSAGE: LIBS -L../test/debug -ltest
    Project MESSAGE: pwd: C:/CPP/Test/App

    my Links
    INCLUDEPATH += ../test
    LIBS += -L../test/debug -ltest

    go to C:/CPP/Test/

    and the library seems to get created in a completely different folder
    C:\CPP\Test\build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\debug

    I dont understand how that should be and how I can fix it

    target in my app.pro is App
    TARGET = App

    and in test.pro it is Test
    TARGET = Test

    I tried copying a version of the Test.lib file into C:/CPP/Test/Test and C:/CPP/Test/App but that also did not help

    I also tried to just add it automatically. That did the trick. Loos like it needed the built paths

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/release/ -lTest
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug/ -lTest
    else:unix: LIBS += -L$$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/ -lTest

    INCLUDEPATH += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug
    DEPENDPATH += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug

    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/release/libTest.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug/libTest.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/release/Test.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug/Test.lib
    else:unix: PRE_TARGETDEPS += $$PWD/../build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/libTest.a


  • Qt Champions 2017

    @zicx said in static library. no such file or directory:

    I dont understand how that should be and how I can fix it

    It should be how you configured it. I ordinarily use shadow building so everything is in one single directory, however there's no "right" way if that's what you're asking. One thing you could do is to reconfigure your library project so it gets built in C:/CPP/Test/test/debug instead of being built in C:/CPP/Test/build-Test-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/debug, or changing the library include paths (the -L switch of the LIBS variable) to match the directory in which the library is actually created. Both approaches should work flawlessly, so it's up to you.

    Kind regards.



  • @kshegunov

    Thanks. Agree that changing the build directory is a good way to structure things. just found out how;)



  • @zicx

    I am still getting confused by this. Now I try to use a static library in another static library. copied over the app.pro lines, but it says
    Cannot open include file test_2.h: No such file or directory

    Any idea why that does not work? This all seems unnecessarily confusing



  • @zicx
    In general it is always a bit confusing when you are using relative path' because you are very often not based in the folder you are expecting.

    @kshegunov has posted already

    message("pwd: " $$PWD)
    

    This allows you to see where you are actually based. Your last message does not hold enough information for giving you better advise, but most likely there is an issue with your folders and relative path'.



  • @koahnig

    Thanks a lot for your comment

    message("pwd in SharedLib.pro: " $$PWD) 
    
     #automatically generate by QT when 'adding library' (via right click on the project  
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SharedLib_2/release/ -lSharedLib_2
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SharedLib_2/debug/ -lSharedLib_2
    
    INCLUDEPATH += $$PWD/../SharedLib_2
    DEPENDPATH += $$PWD/../SharedLib_2
    
    # also added direct path now since it was suggested rel path makes issues 
    win32:CONFIG(release, debug|release): LIBS += -LC:/CPP/Test/SharedLib_2/release/ -lSharedLib_2
    else:win32:CONFIG(debug, debug|release): LIBS += -LC:/CPP/Test/SharedLib_2/debug/ -lSharedLib_2
    
    INCLUDEPATH += C:/CPP/Test/SharedLib_2
    DEPENDPATH += C:/CPP/Test/SharedLib_2
    

    This is the output from the message from SharedLib.pro

    Project MESSAGE: pwd in SharedLib.pro:  C:/CPP/Test/SharedLib
    

    This is what I get from the message in the application file Test.app

    Project MESSAGE: pwd in test.pro:  C:/CPP/Test/Test
    

    The file SharedLib_2 is building in

    C:\CPP\Test\SharedLib_2\debug
    

    Where .dll and library files can be found. The sharedlib_2.h file is in

    C:\CPP\Test\SharedLib_2
    

    As you suggested, I added a manual includepat and dedpendpath but I still get

    C:\CPP\Test\SharedLib\sharedlib.cpp:4: error: C1083: Cannot open include file: 'sharedlib_2.h': No such file or directory
    

    btw, I am running this on windows. QT seems to like the / when creating paths automatically, so I used that as well



  • @zicx

    In .pro files you should use '/' as folder separation. Windows is traditionally using '' but the qmake is following the linux way of declaration (history of early days). Anway Windows can work also with the '/' notation and this makes live much easier. qmake will consider in most cases as continuation line.

    Looks like you should do a complete rerun of qmake for all projects and do a complete a rebuild. My guess is that something went wrong and the created make-files are not up-to-date.



  • That fixed it. I assumed qmake runs on all files, so I may not have run it on that specific file. Thanks a lot.


Log in to reply