组合到Wt示例时的链接错误

时间:2012-12-03 04:08:53

标签: c++ cmake linker-errors wt

我正在为我的项目使用C ++ webframework。 我正在尝试将身份验证添加到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之后。 我试图将link.txt与gitmodel示例和hangman示例结合使用,因为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

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

看起来您没有将User.C包含为源文件?你也可能无意中离开了

DBO_EXTERN_TEMPLATES(User);

在你的头文件中,没有任何相应的

DBO_INSTANTIATE_TEMPLATES(User);

推荐的解决方案:删除所有DBO_EXTERN_TEMPLATES(...)行。