节俭生成的代码未定义的参考
Thrift generated code undefined reference
我正在尝试编写一些代码来使用节俭生成的代码,但我要获得的只是生成代码的错误。我使用的是Thrift 0.10.0和G 5.4.1。
错误:
server/libserver.a(TalkService.cpp.o): In function `std::less<lineserver::Contact>::operator()(lineserver::Contact const&, lineserver::Contact const&) const':
TalkService.cpp:(.text._ZNKSt4lessIN10lineserver7ContactEEclERKS1_S4_[_ZNKSt4lessIN10lineserver7ContactEEclERKS1_S4_]+0x23): undefined reference to `lineserver::Contact::operator<(lineserver::Contact const&) const'
collect2: error: ld returned 1 exit status
CMakeFiles/testshit.dir/build.make:99: recipe for target 'testshit' failed
make[2]: *** [testshit] Error 1
CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/testshit.dir/all' failed
make[1]: *** [CMakeFiles/testshit.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
目录树:
├── app
│ └── main.cpp
├── CMakeLists.txt
└── server
├── CMakeLists.txt
├── line_constants.cpp
├── line_constants.h
├── line_types.cpp
├── line_types.h
├── TalkService.cpp
└── TalkService.h
app/main.cpp:
#include <iostream>
#include <thrift/transport/THttpClient.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TTransportUtils.h>
#include <boost/algorithm/string.hpp>
#include "../server/TalkService.h"
using namespace std;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace lineserver;
int main()
{
boost::shared_ptr<TTransport> socket(new THttpClient("https://gd2.line.naver.jp", 443, "/api/v3/TalkService.do"));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
TalkServiceClient client(protocol);
return 0;
}
cmakelists.txt:
cmake_minimum_required(VERSION 3.8)
project(testshit)
set(CMAKE_CXX_STANDARD 11)
find_library(THRIFT thrift)
include_directories(server app)
link_directories(server app)
add_subdirectory(server)
set(SOURCE_FILES app/main.cpp)
add_executable(testshit ${SOURCE_FILES})
target_link_libraries(testshit ${THRIFT} server)
服务器/cmakelists.txt:
find_library(THRIFT thrift)
file(GLOB SRC_FILES line_constants.cpp line_types.cpp TalkService.cpp)
add_library(server ${SRC_FILES})
target_link_libraries(server ${THRIFT})
用于生成的旧约文件: line.thrift
我真的很喜欢这个帮助,因为我已经试图找出解决方案了一段时间。
可能是您周围/传输创建周围有一些混乱(看来您正在使用Transport类型创建套接字)。
您应该尝试在客户端创建以下内容的通信堆栈:
boost::shared_ptr<TSocket> socket(new TSocket("host", "port"));
boost::shared_ptr<TTransport> transport = boost::shared_ptr<TTransport>(new THttpClient("https://gd2.line.naver.jp", 443, "/api/v3/TalkService.do"));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
TalkServiceClient client(protocol);
设置"主机"answers"端口"值,在您的情况下需要。遵循此创建模式,我成功使用了节俭。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在何处更改参考代码以从 HEVC 编码的视频中提取运动矢量
- 是否有一种方法可以避免在RVALUE和LVALUE参考中创建功能时避免重复的代码
- 为什么认为参考文献在C 底漆第5个中没有变化,以下代码有效
- 为什么此C 代码不起作用 - 试图删除集合中的元素时,请参考错误
- 节俭生成的代码未定义的参考
- C++运算符逗号/转发参考代码无法编译
- 这段代码应该做什么?(参考右值)
- 需要参考:自动代码生成器C++