#defineをライブラリからメインアプリケーションに渡す必要があります。私が理解する限り、これは.prlファイルで実現できます。 私はそれをテストするための簡単なサブディレクトリのプロジェクトを作成しました:QMakeは静的ライブラリの.prlファイルをどのように処理しますか?
これは、メインプロジェクトファイルです:
:これは、メインアプリケーションファイルであるQT -= gui
TARGET = lib
TEMPLATE = lib
# Added create_prl option
CONFIG += staticlib create_prl
# This is the define I want to pass to main application
PRL_EXPORT_DEFINES += TEST_PRL_DEFINE
SOURCES += lib.cpp
HEADERS += lib.h
:これは、ライブラリプロジェクトファイルである
TEMPLATE = subdirs
SUBDIRS += \
app \
lib
app.depends = lib
QT += core
QT -= gui
CONFIG += c++11
TARGET = app
# Added link_prl option
CONFIG += console link_prl
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../lib/release/ -llib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../lib/debug/ -llib
else:unix: LIBS += -L$$OUT_PWD/../lib/ -llib
INCLUDEPATH += $$PWD/../lib
DEPENDPATH += $$PWD/../lib
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/liblib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/liblib.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/lib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/lib.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../lib/liblib.a
しかし、私がプロジェクトをビルドすると(Qt Creatorで問題がある場合)、#定義する標準的なものを除いて、メインアプリケーションに渡されるようだ:
cd lib\ && (if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\lib\lib.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
# Here you can see that TEST_PRL_DEFINE is added to defines of library project
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DTEST_PRL_DEFINE -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\lib" -I"." -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\lib.o ..\..\test_prl\lib\lib.cpp
ar -ru debug\liblib.a debug/lib.o
ar: creating debug\liblib.a
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
cd app\ && (if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\app\app.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
# Here no TEST_PRL_DEFINE is added to #defines of main application project
g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\app" -I"." -I"..\..\test_prl\lib" -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\..\test_prl\app\main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\app.exe debug/main.o -LC:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app/../lib/debug/ -llib -LC:/Qt/5.4/mingw491_32/lib -lQt5Cored
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
しかし、lib.prl
ファイルは、ビルドプロセス中に作成され、liblib.a
の隣に配置。
create_prl/link_prlオプションの使用方法を教えてください。
質問者が 'qmake'を使いたいので、あなたの答えは問題の範囲外です。 – eyllanesc