2

我正在为我的项目使用 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
4

2 回答 2

1

看起来链接器没有找到 Dbo 符号。

如果您使用 cmake 进行编译,能否提供您的 CMakelist.txt?

查看 gitmodel Cmakelist 和 auth Cmakelist 示例,将wtdbowtdbosqlite3添加到 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)
于 2012-12-03T09:47:02.347 回答
0

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

DBO_EXTERN_TEMPLATES(User);

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

DBO_INSTANTIATE_TEMPLATES(User);

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

于 2012-12-24T12:24:04.817 回答