QtCreator - Compiling Issue - External source files



  • I have a Qt project, accessing another cross-platform (boost) project on my disc. Adding the header includes does not seem to cause any problem.

    #include "../../Visual Studio 2015/Projects/..." //Header file down the road
    

    Adding existing source files to the sources folder in my Qt Project works also without a problem, the files are found and I can open them. But these source files are not compiled, as a linker error clearly states (IMO).

    LNK1104: cannot open file 'debug\Error.obj'
    

    Copying the content of (here Error.cpp) the source file in a new file in the Qt-Project directory and adding it solves the problem, though that would mean having to copy each time I pull the other project's changes with git or make changes myself. That misses the purpose of including external source files.

    I have already asked this question on stackoverflow without much luck. One suggestion was to create a ".pri" file and include this file in the Qt-project's ".pro" file. The best I got out of this was a change of the linker error from 1104 to 1181, both unable to open the ".obj" file.

    Has someone experienced this behaviour before or has a hint to a possible solution ?


  • Moderators

    Hi @Blacktempel, and welcome to the Qt Dev Net!

    The correct way to link to external libraries is described at http://doc.qt.io/qt-5/third-party-libraries.html. In a nutshell, you should set the INCLUDEPATH and LIBS variables in your *.pro file.

    @Blacktempel said:

    #include "../../Visual Studio 2015/Projects/..." //Header file down the road

    After you set INCLUDEPATH, you don't need such a long #include line anymore.



  • Hello @JKSH,

    thank you for your answer. This is no library, these are just external source files which have to be compiled together with my Qt-project. The boost headers and libs are already correctly included. Setting the INCLUDEPATH variable only changes the length of the header include and source file include in the *.pro file.
    Trying to set the correct path to the boost-directories root directory and adding the source files with a "short path" results in a failure to find the files at all, which is... a little strange but I was already there. (Paths are correct)
    If I use the "long" path, the files are found, but not compiled.

    INCLUDEPATH += //all other include paths \
                   "../../Visual Studio 2015/Projects/ProjectDir/"
    
    SOURCES += //all other sources \
               Shared/Net/Error.cpp
    //or using 
               ProjectDir/Net/Error.cpp
    

    results in "Failure to find: %filenameWithShortPath%".


  • Moderators

    Hi @Blacktempel,

    I see, I misread your original post.

    One suggestion was to create a ".pri" file and include this file in the Qt-project's ".pro" file. The best I got out of this was a change of the linker error from 1104 to 1181, both unable to open the ".obj" file.

    What happens if you try this solution again, after moving/copying the external source files to a path that does not contain any spaces?



  • Hi @JKSH,

    changing the include in the *.pro file to a path without spaces seemed to work, thank you.
    As test I copied the project to C:

    //This apparently works and source files are compiled.
    include(C:/ProjDir/ProjName.pri)
    //This works too, but the source files are not being compiled.
    include("../../Visual Studio 2015/Projects/ProjDir/ProjName.pri")
    

    Is that an existing bug in "include" ?
    Is there currently no way to include external source files where the path has space[s] in it ?


  • Moderators

    @Blacktempel said:

    Is that an existing bug in "include" ?
    Is there currently no way to include external source files where the path has space[s] in it ?

    I'm not sure; I have never used the include() function with space-containing paths.

    You can ask the Qt engineers by subscribing to the Interest mailing list and posting there.


Log in to reply
 

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