赞
踩
protoc
将 xxx/yy.proto
编译为 yy.pb.cc
和 yy.pb.h
之后 #include 导入会存在一些问题
这样编译可以成功:
g++ -fdiagnostics-color=always -g # Generate source-level debug information 生成源代码级别的调试信息 xxx/lane_cpp.cpp xxx/numpy2cpp.cpp xxx/yewu.cpp xxx/yy.pb.cc -o # 输出可执行文件的名字 xxx/lane_cpp # 关于 -L,-l,-I 请继续往下看 -L/usr/local/lib -lcnpy -lz -L/opt/homebrew/Cellar/protobuf/21.5/lib -lprotobuf -I /opt/homebrew/include -I /opt/homebrew/Cellar/protobuf/21.5/include --std=c++17 # C++ 17 标准
两个-I
选一个就行,因为一个google文件夹是另一个google文件夹的软链接:
xxx@xx include % ls -al
total 0
drwxrwxr-x 4 rx admin 128 9 7 21:18 .
drwxrwxrwx 31 rx admin 992 9 7 21:16 ..
-rw-r--r-- 1 rx admin 0 9 7 21:18 .keepme
lrwxr-xr-x 1 rx admin 38 9 7 21:18 google -> ../Cellar/protobuf/21.5/include/google
xxx@xx include % pwd
/opt/homebrew/include
两个-I
都不加,会有:
In file included from x.cpp:19:
y.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from y.pb.cc:4:
y.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
一些 include
的位置会找不到,-I
是指定用来找 include 文件的路径的
不加 -lprotobuf
会报一系列的错,我放一部分:
Undefined symbols for architecture arm64:
"google::protobuf::RepeatedField<float>::InternalSwap(google::protobuf::RepeatedField<float>*)", referenced from:
...
google::protobuf::Message::Message() in xxxx.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
不加 -L/opt/homebrew/Cellar/protobuf/21.5/lib
会找不到 protobuf
ld: library not found for -lprotobuf
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-L
用来指定刚刚 -lprotobuf
的位置
看下这个路径 /opt/homebrew/Cellar/protobuf/21.5/lib
.a
应该是MAC的静态库.dylib
应该是MAC的动态库本文参考了这篇文章:
https://stackoverflow.com/questions/6141147/how-do-i-include-a-path-to-libraries-in-g
这篇文章把-I
, -L
, -l
给说清楚了,nice!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。