我有3个要编译的文件:
main.cc
transcoder.hpp
transcoder.cc
我正在运行的g ++命令是:
g++ -c -Wall -g transcoder.cc transcoder.hpp -I. -lboost_system -pthread
g++ -c -Wall -g main.cc -I. -lboost_system -pthread
g++ -o main main.o transcoder.o -I. -lboost_system -pthread
在最后一行之后,当main.cc中的代码试图调用transcoder.hpp / transcoder.cc中定义的函数时,我得到一个未定义的错误引用错误。有谁知道我做错了什么?
编辑以添加代码段:
transcoder.hpp
#include <boost/network/protocol/http/server.hpp>
namespace transcoder {
template<class T>
class Transcoder {
public:
void HandleRequest(const typename ::boost::network::http::server<T>::request& request,
typename ::boost::network::http::server<T>::response* response);
};
} // namespace transcoder
transcoder.cc
namespace transcoder {
using boost::network::http::server;
template<class T>
void Transcoder<T>::HandleRequest(const typename server<T>::request& request,
typename server<T>::response* response) {
// random implementation
}
} // namespace transcoder
main.cc
const server<Handler>::request request;
server<Handler>::response response
::transcoder::Transcoder<Handler> transcoder;
transcoder.HandleRequest(request, &response);
确切的错误消息:
main.o: In function `(anonymous namespace)::Handler::operator()(boost::network::http::basic_request<boost::network::http::tags::http_server> const&, boost::network::http::basic_response<boost::network::http::tags::http_server>&)':
/some_dir/main.cc:16: undefined reference to `transcoder::Transcoder<(anonymous namespace)::Handler>::HandleRequest(boost::network::http::basic_request<boost::network::http::tags::http_server> const&, boost::network::http::basic_response<boost::network::http::tags::http_server>*)'