2012-12-03 26 views
2

我正在爲我的項目使用C++ webframework。 我正在嘗試將身份驗證添加到gitmodel示例。與Wt示例相結合的鏈接錯誤

我收到以下錯誤:

../hangman/CMakeFiles/hangman.wt.dir/Session.o: In function `Session::Session()':  /home/s/Downloads/wt-3.2.3/examples/hangman/Session.C:101: undefined reference to `void Wt::Dbo::Session::mapClass<User>(char const*)' 
../hangman/CMakeFiles/hangman.wt.dir/Session.o: In function `Wt::Auth::Dbo::AuthInfo<User>::user() const': /home/s/Downloads/wt-3.2.3/src/Wt/Auth/Dbo/AuthInfo:94: undefined reference to `Wt::Dbo::ptr<User>::ptr(Wt::Dbo::ptr<User> const&)' 
../hangman/CMakeFiles/hangman.wt.dir/Session.o: In function `Session::user() const': /home/s/Downloads/wt-3.2.3/examples/hangman/Session.C:138: undefined reference to `Wt::Dbo::ptr<User>::operator bool() const' 
/home/s/Downloads/wt-3.2.3/examples/hangman/Session.C:139: undefined reference to `User::User()' 
/home/s/Downloads/wt-3.2.3/examples/hangman/Session.C:139: undefined reference to `Wt::Dbo::ptr<User> Wt::Dbo::Session::add<User>(User*)' 
/home/s/Downloads/wt-3.2.3/examples/hangman/Session.C:139: undefined reference to `Wt::Dbo::ptr<User>::operator=(Wt::Dbo::ptr<User> const&)' 

完整的錯誤列表:http://pastie.org/5469803

我試圖使用生成的makefile CMake的。追查下來後,發現這個鏈接器錯誤是在CMakeFiles目錄下運行link.txt之後發生的。 我試圖將gitmodel示例和hangman示例的link.txt結合起來,因爲hangman也進行身份驗證。 這裏是我的link.txt:

/usr/bin/c++ -O2 -g ../hangman/CMakeFiles/hangman.wt.dir/Session.o CMakeFiles/gitview.wt.dir/Git.o CMakeFiles/gitview.wt.dir/GitModel.o CMakeFiles/gitview.wt.dir/__/wt-homepage/SourceView.o CMakeFiles/gitview.wt.dir/GitView.o -o gitview.wt -rdynamic -L/home/s/Downloads/wt-3.2.3/build/src/http -L/home/s/Downloads/wt-3.2.3/build/src -L/home/s/Downloads/wt-3.2.3/build/src/Wt/Dbo -L/home/s/Downloads/wt-3.2.3/build/src/Wt/Dbo/backend -lcrypt -L/usr/local/lib ../../src/http/libwthttp.so.3.2.3 ../../src/libwt.so.3.2.3 ../../src/Wt/Dbo/libwtdbo.so.3.2.3 ../../src/Wt/Dbo/backend/libwtdbosqlite3.so.3.2.3 /usr/local/lib/libboost_filesystem.so /usr/local/lib/libboost_random.so /usr/local/lib/libboost_regex.so /usr/local/lib/libboost_signals.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_filesystem.so -lz -lssl -lcrypto ../../src/Wt/Dbo/libwtdbo.so.3.2.3 /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_program_options.so /usr/local/lib/libboost_date_time.so -lpthread -ldl -Wl,-rpath,/home/s/Downloads/wt-3.2.3/build/src/http:/home/s/Downloads/wt-3.2.3/build/src:/home/s/Downloads/wt-3.2.3/build/src/Wt/Dbo:/home/s/Downloads/wt-3.2.3/build/src/Wt/Dbo/backend:/usr/local/lib 

Pastie鏈接:http://pastie.org/5469815

誰能告訴這有什麼錯我的鏈接命令?

上運行cmake的, 我得到

/home/s/Downloads/wt-3.2.3/examples/gitmodel on master ✗ at 1:24PM 
➜ BOOST_FS_LIB=/usr/local/lib/libboost_filesystem.so cmake . 
-- ** Not building gitmodel example: requires boost_filesystem library. 
CMake Warning (dev) in CMakeLists.txt: 
    No cmake_minimum_required command is present. A line of code such as 

    cmake_minimum_required(VERSION 2.8) 

should be added at the top of the file. The version specified may be lower 
if you wish to support older CMake versions for this project. For more 
information run "cmake --help-policy CMP0000". 
This warning is for project developers. Use -Wno-dev to suppress it. 

-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/s/Downloads/wt-3.2.3/examples/gitmodel 

回答

1

看起來接頭沒有找到DBO符號。

如果你用cmake編譯,你能否提供你的CMakelist.txt?

看着gitmodel Cmakelist並權威性Cmakelist例子,它應該是足夠加入wtdbowtdbosqlite3到TARGET_LINK_LIBRARIES。

[email protected]:~$ cat /usr/lib/Wt/examples/gitmodel/CMakeLists.txt 
IF(NOT WIN32) 

IF(BOOST_FS_LIB) 
    WT_ADD_EXAMPLE(gitview.wt 
    Git.C 
    GitModel.C 
    ../wt-homepage/SourceView.C 
    GitView.C 
) 
TARGET_LINK_LIBRARIES(gitview.wt ${BOOST_FS_LIB} ${BOOST_SIGNALS_LIB} ${BOOST_SYSTEM_LIB}) 

INCLUDE_DIRECTORIES(
    ${WT_SOURCE_DIR}/src 
) 

ADD_DEPENDENCIES(gitview.wt wt ${EXAMPLES_CONNECTOR}) 

ELSE(BOOST_FS_LIB) 

    MESSAGE(STATUS "** Not building gitmodel example: requires boost_filesystem library.") 

ENDIF(BOOST_FS_LIB) 

ELSE(NOT WIN32) 

    MESSAGE(STATUS "** Not building gitmodel example: uses POSIX calls not available on win32") 

ENDIF(NOT WIN32) 

[email protected]:~$ cat /usr/lib/Wt/examples/feature/auth1/CMakeLists.txt 
WT_ADD_EXAMPLE(auth1.wt 
     Auth1.C 
    model/Session.C 
    model/User.C 
) 

TARGET_LINK_LIBRARIES(auth1.wt wtdbo wtdbosqlite3 ${BOOST_SIGNALS_LIB} ${BOOST_SYSTEM_LIB}) 

INCLUDE_DIRECTORIES(${WT_SOURCE_DIR}/src) 
+0

正在運行cmake,我得到 – snihalani

+0

在問題中添加了cmake輸出。 – snihalani

+0

另外,看起來像你在/ usr/lib中安裝你的例子?你是怎麼做到的?任何鏈接將不勝感激。文檔似乎不起作用。謝謝。 – snihalani

0

它看起來像你不包括User.C作爲源文件?你也可能無意地

DBO_EXTERN_TEMPLATES(User); 
在你的頭文件

,而無需任何地方相應

DBO_INSTANTIATE_TEMPLATES(User); 

推薦分辨率:刪除所有DBO_EXTERN_TEMPLATES(...)線。