2017-05-24 10 views
0

Linux에서 autotools (많은 프로젝트를 수행 했음)를 사용하여 기본 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는 애플 리케이션을하지, 그래서 난 내 MainWindow를 헤더의 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는 내가 전에도이/승 불평 할 것이다

컴파일하려고 ...

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 

당신은 또한 다른 사람들이 뒤에 남아있을 것입니다, 당신의 CLEANFILES 중 내장 소스를 나열 할 수 있습니다 때 make clean.