Qt Creator Manual

Adding Libraries to Projects

In addition to Qt libraries, you can add other libraries to your projects. The way the library is added depends on whether it is a system library or your own library or a 3rd party library located in the build tree of the current project or in another build tree.

"Add Library wizard"

Because system libraries do not typically change and are often found by default, you do not need to specify the path to the library or to its includes when you add it.

For your own libraries and 3rd party libraries, you need to specify the paths. Qt Creator tries to quess the include path for an external library, but you need to check it and modify it if necessary. Qt Creator automatically adds the include path for an internal library.

For all libraries, select the target platforms for the application, library, or plugin.

Specify whether the library is statically or dynamically linked. For a statically linked internal library, Qt Creator adds dependencies (PRE_TARGETDEPS) in the project file.

Depending on the development platform, some options might be detected automatically. For example, on Mac OS, the library type (Library or Framework) is detected automatically and the option is hidden. However, if you develop on another platform than Mac OS and want to build your project for the Mac OS, you must specify the library type.

The default convention on Windows is that the debug and release versions of a library have the same name, but are placed in different subdirectories, usually called debug and release. If the library path does not contain either of these folders, you cannot select the option to place the libraries in separate folders.

Alternatively, the letter d can be added to the library name for the debug version. For example, if the release version is called example.lib, the debug version is called exampled.lib. You can specify that the letter is added for the debug version and removed for the release version. If the library name ends in d, deselect the Remove "d" suffix for release version option.

Qt Creator supports code completion and syntax highlighting for the added libraries once your project successfully builds and links to them.

To Add Libraries

  1. In the Projects pane, open the project file (.pro).
  2. Right-click in the code editor to open the context menu and select Add Library....
  3. Follow the instructions of the wizard.

For more information about the project file settings, see Declaring Other Libraries.

Example of Adding Internal Libraries

The following example describes how to add a statically linked internal library to your project.

  1. Choose File > New File or Project... > Other Projects > C++ Library to create the library.

    The Introduction and Product Location dialog opens.

    "Introduction and Product Location dialog"

  2. In the Type field, select Statically Linked Library.
  3. In the Name field, give a name for the library. For example, mylib.
  4. Follow the instructions of the wizard until you get to the Project Management dialog. In the Add to project list, select a project. For example, myapp.
  5. In the Projects pane, open the project file (.pro). For example, myapp.pro.
  6. Right-click in the code editor to open the context menu and select Add Library... > Internal Library > Next.
  7. In the Library field, select mylib and click Next.
  8. Click Finish to add the following library declaration to the project file:
     win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../projects/mylib/release/ -lmylib
     else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../projects/mylib/debug/ -lmylib
     else:symbian: LIBS += -lmylib
     else:unix: LIBS += -L$$OUT_PWD/../../../projects/mylib/ -lmylib
    
     INCLUDEPATH += $$PWD/../../../projects/mylib
     DEPENDPATH += $$PWD/../../../projects/mylib
    
     win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../projects/mylib/release/mylib.lib
     else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../projects/mylib/debug/mylib.lib
     else:unix:!symbian: PRE_TARGETDEPS += $$OUT_PWD/../../../projects/mylib/libmylib.a
X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

[0]; s.parentNode.insertBefore(ga, s); })();