チュートリアル:qmake での内部ライブラリの使用方法
subdirsプロジェクトにライブラリを追加することができます。ウィザードを使用して、プロジェクトとライブラリを作成し、そのライブラリをプロジェクトにリンクさせます。
注:この チュートリアルは 、subdirs プロジェクトのビルドシステムとして qmake を選択した場合にのみ適用されます。
共有ライブラリの作成
共有ライブラリを作成するには:
- 「File 」>「New Project 」に移動し、「Library 」>「C++ Library 」を選択します。最上位プロジェクトがサブディレクトリプロジェクトであるか、またはサブディレクトリプロジェクトを含む場合、そのプロジェクトにライブラリを追加できます。ただし、この操作では、プロジェクト内の他のライブラリをそのライブラリに対してリンクすることはありません。
- 「Choose 」を選択して、「Project Location 」ダイアログを開きます。
![[プロジェクトの場所] ダイアログ [プロジェクトの場所] ダイアログ](images/qtcreator-add-library-internal-project-location.webp)
- 「Name 」で、ライブラリに名前を付けます。例:MyLibrary。
- 「Next 」(Windows および Linux)または「Continue 」(macOS)を選択して、「Define Build System 」ダイアログを開きます。
- 「Build system 」で、「qmake 」を選択します。
- 「Next 」または「Continue 」を選択して、「Define Project Details 」ダイアログを開きます。

- ライブラリの種類を選択し、ソースコードファイルを生成したいクラスに関する情報(クラス名、Qt モジュール、ソースファイル名およびヘッダーファイル名)を入力します。
- 「Next 」または「Continue 」を選択し、「Project Management 」ダイアログが表示されるまで進みます。「Add as a subproject to project 」リストから、subdirs プロジェクトを選択します。例:MyApplication。
アプリケーションをライブラリにリンクする
プロジェクトを共有ライブラリにリンクするには:
- 「Projects」ビューで、プロジェクト名を右クリックしてコンテキストメニューを開き、「Add Library 」 > 「Internal Library 」 > 「Next 」の順に選択します。
ウィザードにより、ビルドシステムに対して、既存のアプリケーションプロジェクトまたはライブラリプロジェクトを選択したライブラリに対してリンクするよう指示されます。ここで、上記で作成したライブラリを追加します。

- 「Library 」で「mylibrary」を選択し、次に「Next 」を選択します。
- 「Finish 」を選択して、プロジェクトファイルにライブラリ宣言を追加します。
ウィザードにより、.pro ファイルに以下のライブラリ宣言が追加されます。
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: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: PRE_TARGETDEPS += $$OUT_PWD/../../../projects/mylib/libmylib.a
関連項目: qmake プロジェクトへのライブラリの追加、CMake プロジェクトへのライブラリの追加、プロジェクトへのサブプロジェクトの追加、ビルドシステムの選択、プロジェクトウィザードの使用、およびプロジェクトの作成。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.