g++版本7.4.0
编译命令
g++ -c -std=c++11 -O3 -o myport myport.cpp -lrt -lpthread -Icore -Lcore
报错部分:
In file included from /usr/include/ctype.h:39:0,
from /usr/include/c++/7/cctype:42,
from /usr/include/c++/7/bits/localefwd.h:42,
from /usr/include/c++/7/string:43,
from core/***.h:26,
from core/***.h:4,
from myport.cpp:4:
core/***.h:29:1: error: template with C linkage
template<bool ToLittle>
^~~~~~~~
In file included from core/***.h:30:0,
from core/***.h:4,
from myport.cpp:4:
/usr/include/netinet/tcp.h:102:17: error: redeclaration of ‘ uint8_t tcphdr::<unnamed union>::<unnamed struct>::th_off ’
uint8_t th_off:4; /* data offset */
^
/usr/include/netinet/tcp.h:99:17: note: previous declaration ‘ uint8_t tcphdr::<unnamed union>::<unnamed struct>::th_of ’
uint8_t th_off:4; /* data offset */
^
/usr/include/netinet/tcp.h:103:16: error: redeclaration of ‘ uint8_t tcphdr::<unnamed union>::<unnamed struct>::th_x2 ’
uint8_t th_x2:4; /* (unused) */
^
/usr/include/netinet/tcp.h:98:16: note: previous declaration ‘ uint8_t tcphdr::<unnamed union>::<unnamed struct>::th_x2 ’
uint8_t th_x2:4; /* (unused) */
由于强行转的 c/c++,很多基础不知道,来求助一下大佬们。迫于保密,部分已打码。
看描述有两个问题:
搜了下,这个很多是 extern "C"导致的,我这边的是:
#ifdef __cplusplus
extern "C" {
#endif
#include "myport.h"
#ifdef __cplusplus
}
#endif
整段去掉都没用
#include <string>
#include <strings.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h> <-- 这行是 core/***.h:30:0
#include <arpa/inet.h>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.