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++,很多基础不知道,来求助一下大佬们。迫于保密,部分已打码。
看描述有两个问题:
1. error: template with C linkage
搜了下,这个很多是 extern "C"导致的,我这边的是:
#ifdef __cplusplus
extern "C" {
#endif
#include "myport.h"
#ifdef __cplusplus
}
#endif
整段去掉都没用
2. 报错地点引用了以下头文件
#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>