Paths/properties required when compiling with shared library



  • I have a subdirs project with two current sub-projects - my main application and a library.

    http://i.imgur.com/j0XlBTW.png

    On disk, I have both sub-projects together under the source directory, which get compiled into their respective folders in the build directory.

    http://i.imgur.com/MSQNtZq.png

    Application source is red, build is green; library source is purple, build is blue. The application .pro file resides in the app directory in the red square, and the library .pro file in the IConsole directory in the purple square.

    My library will be a shared library, so I gather that I'll have to link the application to its lib/header files on compile and place the library DLL into the application directory when I run it. However, I'm getting a bit confused with what I need to specify in the application pro file in order to compile correctly. I have compiled the library sub-project without issue, but at the moment Qt Creator suggests the library header files when I try and #include them in the application sub-project, even though I haven't added the INCLUDEPATHS entry yet, and the headers cannot be found when the application sub-project is compiled. I'm also not sure what to specify for the LIBS entry as I'm not sure whether the path needs to be relative to the source or build directory of the application.

    My application .pro file also contains the following:

    @if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
    mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)_debug
    win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d
    }@

    I'm wondering whether the "=" should be changed to "+=" so that it doesn't override the LIBS variable, but I'm not sure.

    Could anyone give me any pointers to how I should configure the .pro file? I need to know what directory the INCLUDEPATHS variable treats as the root direcrory (same for LIBS) and what format the LIBS parameters need to be in - I know -L is for folders and -l for the files, but do the folders need preceding "/" characters and do the libraries need the ".lib" extension?

    Thanks.


  • Moderators

    INCLUDEPATH's root dir is the directory where your .pro file is located (if you are including it in a .pri file, it still will be based on the location of the .pro).

    For LIBS, you do indeed need to use "+=". It should also be relative to the .pro file (actual loading of the library during runtime is something the OS manages, Qt has no influence there. LIBS are only relevant to the linker, which will be looking for library object files).


Log in to reply
 

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