未找到带有google协议缓冲区的gcc头文件
gcc header file not found with google protocol buffer
我正试图使用gcc
命令编译并运行一个.cpp
文件来测试googleprotobuf。
CPP_TEST.CPP
#include "GameInfo.pb.h"
int main() {
// ...
}
protoc
生成的GameInfo.pb.h
#ifndef PROTOBUF_GameInfo_2eproto__INCLUDED
#define PROTOBUF_GameInfo_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
// ...
我在文件夹中的文件看起来像这个
- test
CPP_TEST.cpp
GameInfo.pb.h
GameInfo.pb.cc
// the lib file for protobuf
libprotobuf.a
// the srouce code of protobuf
- google
- protobuf
// ...
- stubs
common.h
// ...
然后我尝试编译.cpp
文件
gcc CPP_TEST.cpp -l ./google -o OUT_CPP_TEST
但是得到错误:
#include <google/protobuf/stubs/common.h>
'google/protobuf/stubs/common.h' file not found with <angled> include; use "quotes" instead
我认为这是gcc编译器标志的错误,但不知道为什么。。。
任何建议都将不胜感激,谢谢:)
更新:
将命令更改为后
gcc CPP_TEST.cpp -I./ -o OUT_CPP_TEST
该文件可以编译并运行。
但如果我给main
函数添加一个代码:
game::info::GameInfo gameInfoOut;
编译它将失败:
Undefined symbols for architecture x86_64:
"game::info::GameInfo::GameInfo()", referenced from:
_main in CPP_TEST-9245ef.o
"game::info::GameInfo::~GameInfo()", referenced from:
_main in CPP_TEST-9245ef.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
所以我尝试将libprotobuf.a
文件添加到gcc命令中
gcc CPP_TEST.cpp -L./ -lprotobuf -I./ -o CPP_TEST_OUT
但我仍然得到同样的错误:
Undefined symbols for architecture x86_64:
"game::info::GameInfo::GameInfo()", referenced from:
_main in CPP_TEST-0e3576.o
"game::info::GameInfo::~GameInfo()", referenced from:
_main in CPP_TEST-0e3576.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
更新:
我试图一步一步地编译和链接所有文件,比如:
gcc -c -I./ GameInfo.pb.cc
gcc -c -I./ GameEnum.pb.cc
gcc -c -I./ CPP_TEST.cpp
和链接
gcc CPP_TEST.o GameInfo.pb.o GameEnum.pb.o -L./ -lprotobuf -o main
现在我收到了一堆错误,比如:
Undefined symbols for architecture x86_64:
"___dynamic_cast", referenced from:
game::info::RoleInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::RoleInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
game::info::ItemInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::ItemInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
game::info::GameInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::GameInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
google::protobuf::FileDescriptorSet const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::FileDescriptorSet const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::FileDescriptorProto const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::FileDescriptorProto const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::DescriptorProto_ExtensionRange const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::DescriptorProto_ExtensionRange const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::DescriptorProto const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::DescriptorProto const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
...
"___gxx_personality_v0", referenced from:
game::enumeration::protobuf_AssignDesc_GameEnum_2eproto() in GameEnum.pb.o
google::protobuf::GoogleOnceInit(long*, void (*)()) in GameEnum.pb.o
Dwarf Exception Unwind Info (__eh_frame) in GameEnum.pb.o
game::info::protobuf_AssignDesc_GameInfo_2eproto() in GameInfo.pb.o
game::info::protobuf_AddDesc_GameInfo_2eproto() in GameInfo.pb.o
game::info::RoleInfo::RoleInfo() in GameInfo.pb.o
game::info::RoleInfo::RoleInfo(game::info::RoleInfo const&) in GameInfo.pb.o
// more here
这真的很奇怪,因为我可以用所有的GameInfo.pb.h/cc GameEnum.pb.h/c、libprotobuf.a和"谷歌源代码"编译并在xcode中成功运行它。
gcc不知道google头的include目录,直到您提到使用-I
标志而不是-l
的路径。由于google
目录在当前工作目录中,因此不需要为-I
传递./google
。
g++ -I./ CPP_TEST.cpp -o OUT_CPP_TEST
或者,你可以使用你的错误建议(使用引号而不是角度),因为你的文件层次结构与这个建议相匹配。
#include "google/protobuf/stubs/common.h"
相关文章:
- C++字符*缓冲区的大小
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 为什么msgrcv()将垃圾字符馈送到缓冲区
- 奇怪的结构&GCC&clang(void*返回类型)
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- ostream过载时的缓冲区冲洗
- GCC本机矩阵运算库
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- Xaudio2在更改缓冲区或循环时弹出声音
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 使用gcc从静态链接的文件中查找可选符号
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 如何抑制来自 gcc 中地址清理器的堆栈缓冲区溢出
- 未找到带有google协议缓冲区的gcc头文件