与 Wt 示例组合时的链接错误
Posted
技术标签:
【中文标题】与 Wt 示例组合时的链接错误【英文标题】:Linked error on combining to Wt examples 【发布时间】:2012-12-03 04:08:52 【问题描述】:我正在为我的项目使用 C++ 网络框架。 我正在尝试向 gitmodel 示例添加身份验证。
我收到以下错误:
../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
我尝试使用 cmake 生成的 makefile。追查下来,原来这个链接器错误是在运行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
粘贴链接: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 和 auth Cmakelist 示例,将 wtdbo 和 wtdbosqlite3 添加到 TARGET_LINK_LIBRARIES 应该足够了。
user@debiam:~$ 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)
.
user@debiam:~$ 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)
【讨论】:
在问题中添加了 cmake 输出。 另外,看起来您在 /usr/lib 中安装了示例?你是怎么做到的?任何链接将不胜感激。该文档似乎不起作用。谢谢。 这些是 debian 安装的一部分。您可以检查 witty-examples 包中的 debian wt 示例:packages.debian.org/sid/witty-examples Cmake 没有找到 boost-filesystem 库。如果你查看 witty-examples debian 包,你会发现它依赖于 libboost-filesystem1.49.0。例如,如果您可以安装带有 debian-testing 的虚拟机,那么您将更容易尝试。但是如果你打算用 wt 开发,你应该学会使用 cmake(不是那么难)。【参考方案2】:您似乎没有将 User.C 作为源文件包含在内?还有你可能无意中离开了
DBO_EXTERN_TEMPLATES(User);
在你的头文件中,没有任何对应的地方
DBO_INSTANTIATE_TEMPLATES(User);
建议的解决方法:删除所有 DBO_EXTERN_TEMPLATES(...) 行。
【讨论】:
以上是关于与 Wt 示例组合时的链接错误的主要内容,如果未能解决你的问题,请参考以下文章