このページでは

チュートリアルqmakeで内部ライブラリを使う

サブディレクトリのプロジェクトにライブラリを追加することができます。ウィザードを使用してプロジェクトとライブラリを作成し、プロジェクトに対してライブラリをリンクします。

Note: このチュートリアルは subdirs プロジェクトのビルドシステムとして qmake を選択した場合にのみ適用されます。

共有ライブラリーの作成

共有ライブラリを作成するには

  1. File >New Project に移動し、Library >C++ Library を選択します。トップレベルのプロジェクトがサブディレクトリ・プロジェクトであるか、サブディレクトリ・プロジェクトを含んでいる場合、ライブラリをプロジェクトに追加することができます。ただし、この場合、プロジェクトの他のライブラリはリンクされません。
  2. Choose を選択して、Project Location ダイアログを開きます。

    プロジェクトロケーションダイアログ

  3. Name で、ライブラリの名前を指定します。例えば、MyLibrary とします。
  4. Next (Windows および Linux の場合)またはContinue (macOS の場 合)を選択して、Define Build System ダイアログを開きます。
  5. Build system で、qmake を選択します。
  6. Next またはContinue を選択し、Define Project Details ダイアログを開きます。

    プロジェクトの詳細定義ダイアログ

  7. ライブラリ・タイプを選択し、ソース・コード・ファイルを生成するクラスに関する情報(クラス名、 Qt モジュール、ソース・ファイル名およびヘッダー・ファイル名)を入力します。
  8. Project Management ダイアログが表示されるまで、Next またはContinue を選択します。Add as a subproject to project リストで、サブディレクトリのプロジェクトを選択します。例えば、MyApplication です。

プロジェクトを共有ライブラリにリンクするには

  1. プロジェクト・ビューでプロジェクト名を右クリックしてコンテキスト・メニューを開き、Add Library >Internal Library >Next を選択します。

    ウィザードは、既存のアプリケーション・プロジェクトまたはライブラリ・プロジェクトを、選択したライブラリにリンクするようビルド・システムに指示します。ここでは、上記で作成したライブラリを追加します。

    内部ライブラリの追加

  2. Librarymylibrary を選択し、Next を選択します。
  3. 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.