Adding external library into Qt Creator project

后端 未结 8 1777
广开言路
广开言路 2020-11-22 09:39

How can I add external library into a project built by Qt Creator RC1 (version 0.9.2)? For example, the win32 function EnumProcesses() requires Psapi.lib<

相关标签:
8条回答
  • 2020-11-22 10:34

    The proper way to do this is like this:

    LIBS += -L/path/to -lpsapi
    

    This way it will work on all platforms supported by Qt. The idea is that you have to separate the directory from the library name (without the extension and without any 'lib' prefix). Of course, if you are including a Windows specific lib, this really doesn't matter.

    In case you want to store your lib files in the project directory, you can reference them with the $$_PRO_FILE_PWD_ variable, e.g.:

    LIBS += -L"$$_PRO_FILE_PWD_/3rdparty/libs/" -lpsapi
    
    0 讨论(0)
  • 2020-11-22 10:41

    I would like to add for the sake of completeness that you can also add just the LIBRARY PATH where it will look for a dependent library (which may not be directly referenced in your code but a library you use may need it).

    For comparison, this would correspond to what LIBPATH environment does but its kind of obscure in Qt Creator and not well documented.

    The way i came around this is following:

    LIBS += -L"$$_PRO_FILE_PWD_/Path_to_Psapi_lib/"
    

    Essentially if you don't provide the actual library name, it adds the path to where it will search dependent libraries. The difference in syntax is small but this is very useful to supply just the PATH where to look for dependent libraries. It sometime is just a pain to supply each path individual library where you know they are all in certain folder and Qt Creator will pick them up.

    0 讨论(0)
提交回复
热议问题