2013-12-11 18 views
0

我想編譯一個小的Qt例子到一個可執行文件(與test.cpp containg主),並且後來添加支持編譯非test.cpp代碼到它自己的庫。我正在使用qmake,但現在我試圖按照here的示例使用cmake。不幸的是,我收到了鏈接錯誤。看起來像構造函數,我正在編譯的cpp文件中定義的構造函數沒有在鏈接時找到。cmake連接本地文件時未定義的函數

$ make 
Linking CXX executable test 
CMakeFiles/test.dir/attribute_editor.cpp.o: In function `AttributeEditor::AttributeEditor(QWidget*)': 
attribute_editor.cpp:(.text+0x2a): undefined reference to `vtable for AttributeEditor' 
CMakeFiles/test.dir/bindable.cpp.o: In function `Bindable::Bindable(QObject*)': 
bindable.cpp:(.text+0x50): undefined reference to `vtable for Bindable' 
CMakeFiles/test.dir/bindable.cpp.o: In function `AttributeObject::AttributeObject()': 
bindable.cpp:(.text._ZN15AttributeObjectC2Ev[_ZN15AttributeObjectC5Ev]+0x24): undefined reference to `vtable for AttributeObject' 
collect2: error: ld returned 1 exit status 
make[2]: *** [test] Error 1 
make[1]: *** [CMakeFiles/test.dir/all] Error 2 
make: *** [all] Error 2 

這是我的cmake文件...

cmake_minimum_required(VERSION 2.8) 

# http://qt-project.org/quarterly/view/using_cmake_to_build_qt_projects 

PROJECT(qattrs) 
FIND_PACKAGE(Qt4 REQUIRED) 
SET(QT_USE_QTSCRIPT TRUE) 

SET(qattrs_SOURCES test.cpp attribute_editor.cpp bindable.cpp) 
SET(qattrs_HEADERS bindable.h attribute_editor.h) 

QT4_WRAP_CPP(qattrs_HEADERS_MOC ${qattrs_HEADERS}) 

INCLUDE(${QT_USE_FILE}) 
ADD_DEFINITIONS(${QT_DEFINITIONS}) 

ADD_EXECUTABLE(test ${qattrs_SOURCES} ${qattrs_HEADER_MOC}) 
TARGET_LINK_LIBRARIES(test ${QT_LIBRARIES}) 

我不是很瞭解CMake的,但我相信它在連接過程中還不包括.o文件。

整個代碼(五或六個文件)在github上。

回答

0

它無法找到一個vtable的東西 - 這意味着它正在尋找一個類型將放入它的vtable如果存在的條目,因爲它是一個鏈接器。 (這不是說在運行時沒有vtable的類型,因爲根本沒有意義,我甚至不喜歡那句話)

某處你有一個你從未定義過的純虛擬方法。

該代碼真的很難閱讀和閱讀它甚至在bindable.h中也看不到任何虛擬,這意味着在父類中有一個純虛函數,並且您從不實現它,那是您的錯誤。

更具體地說,你永遠不會實現其中的3個。

我會心疼的不是說: wxWidgets的FTW:P

相關問題