2017-05-24 7 views
0

Linux上で(私は多くのプロジェクトでやった)オートツールを使って、基本的なQtアプリケーション(Qtの新機能)をコンパイルしようとしています。Qt mocをautotoolsプロジェクト(2017年)で使用するには?

リンクが始まるまで、すべてがうまくコンパイルされているように見えます。

test-mainwindow.o: In function `MainWindow::MainWindow()': 
mainwindow.cpp:5: undefined reference to `vtable for MainWindow' 
mainwindow.cpp:5: undefined reference to `vtable for MainWindow' 
mainwindow.o: In function `MainWindow::~MainWindow()': 
mainwindow.cpp:11: undefined reference to `vtable for MainWindow' 
mainwindow.cpp:11: undefined reference to `vtable for MainWindow' 
mainwindow.o: In function `MainWindow::tr(char const*, char const*, int)': 
mainwindow.h:10: undefined reference to `MainWindow::staticMetaObject' 
collect2: error: ld returned 1 exit status 
make[4]: *** [Makefile:415: test] Error 1 

私は前のQtアプリをやっていませんでしたので、私は私のメインウィンドウのヘッダーに多分MOCとは何か、またはQ_OBJECTを疑いますか?私がオンラインで見つけたほとんどすべての例は、4歳以上です。

ソースファイルのMakefile.amは次のようになります。

include $(top_srcdir)/common.am 

bin_PROGRAMS = test 

test_SOURCES =    \ 
    main.cpp     \ 
    mainwindow.cpp 

test_CPPFLAGS = -I/usr/include -I/usr/local/include -I$(QT5_INCL) -I$(QT5_INCL)/QtWidgets -I$(QT5_INCL)/QtCore 

test_LDFLAGS = -L/usr/lib64 -L/usr/local/lib64 -L/usr/local/lib -L$(QT5_LIBS) 

test_LDADD = -lrt -lQt5Core -lQt5Gui -lQt5Widgets 

そして私は、私はこの時点ではない、完全に正確であると確信しているMakefile.am、...にこれを追加した場合

moc-%.cpp: %.h 
    /usr/lib64/qt5/bin/moc $(DEFINES) $(INCPATH) $< -o [email protected] 

moc-%.cc: %.h 
    @[email protected] [email protected] $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(MOC_CPPFLAGS) $< 

ui-%.h: %.ui 
    @[email protected] -o [email protected] $< 

qrc-%.cc: %.qrc 
    @[email protected] -o [email protected] $< 
Automakeは私も、前にこの/ wの文句を言うでしょう

コンパイルしよう...

Makefile.am:19: warning: '%'-style pattern rules are a GNU make extension 
Makefile.am:24: warning: '%'-style pattern rules are a GNU make extension 
Makefile.am:27: warning: '%'-style pattern rules are a GNU make extension 
Makefile.am:30: warning: '%'-style pattern rules are a GNU make extension 

誰もがautotoolsのを使用して、物事のMOC一部を実装する方法についてのアイデアを持っていますか?

答えて

1

Automakeは、mocまたは他のQtツールを使用して他のファイルを処理することによって作成する必要のある不特定のソースにプログラムが依存していることを自動的に認識しません。 *_SOURCES変数には、そのような派生元の名前を明示的に指定する必要があります。そのためには、文字通りmakeのルールまたはルールを提供する必要があります。

さらに、変数BUILT_SOURCESの値のうちのいくつかを指定する必要があります。 C++のトップレベルのソースファイルではこの処理は必要ありませんが、ビルドされたヘッダファイル(または#includeディレクティブに指定されている他のソース)が必要です。

詳細は多少あなた次第ですが、具体的な解決方法はご提供できません。お客様のニーズが正確ではないためです。しかし、希望Automakeのファイルは、このようなものに見えるかもしれません:

include $(top_srcdir)/common.am 

bin_PROGRAMS = test 

# headers that must be processed with moc to generate C++ source files 
test_qtheaders = mainwindow.h 

# the source files that will be generated via moc. The string "_moc" is inserted 
# to, hopefully, avoid name collisions 
test_moc_sources = $(test_qtheaders:.h=_moc.cpp) 

test_SOURCES =    \ 
    main.cpp     \ 
    mainwindow.cpp   \ 
    $(test_moc_sources) 

test_CPPFLAGS = -I/usr/include -I/usr/local/include -I$(QT5_INCL) -I$(QT5_INCL)/QtWidgets -I$(QT5_INCL)/QtCore 

test_LDFLAGS = -L/usr/lib64 -L/usr/local/lib64 -L/usr/local/lib -L$(QT5_LIBS) 

test_LDADD = -lrt -lQt5Core -lQt5Gui -lQt5Widgets 

# A traditional-style Make suffix rule for generating *_moc.cpp files from *.h 
# files via moc. For the former (especially) to be recognized as a suffix, 
# you need to tell Automake about it via the `SUFFIXES` variable. 
# The mkdir is present to support out-of-source building. 
# Assumes that the MOC variable will be set by configure. 
.h_moc.cpp: 
    $(MKDIR_P) `dirname [email protected]` 
    $(MOC) -o [email protected] $(test_CPPFLAGS) $(CPPFLAGS) $< 

SUFFIXES = .h _moc.cpp 

またときmake clean彼らは取り残される他、あなたのCLEANFILESの間で構築されたソースをリストすることもできます。

関連する問題