c - 在 ARM 上取消引用指向不完整类型但不是 x86 上的指针

标签 c gcc arm beagleboneblack icmp

<分区>

我在 beaglebone 上编译时遇到了这个错误(当然我已经包含了 netinet/ip_icmp.h ):

src/network.c: In function 'ping':
src/network.c:74:3: warning: implicit declaration of function 'setuid' [-Wimplicit-function-declaration]
src/network.c:74:3: warning: implicit declaration of function 'getuid' [-Wimplicit-function-declaration]
src/network.c:88:6: error: dereferencing pointer to incomplete type
src/network.c:89:6: error: dereferencing pointer to incomplete type
src/network.c:118:14: error: dereferencing pointer to incomplete type

但它只发生在 ARM 平台(beaglebone)上。在我的 x86 上一切正常。 这里有一些有用的信息:

root@beaglebone:~/mips# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14)

84 到 89 行表格 network.c :

struct icmp *pkt;
pkt = (struct icmp *) packet;
memset(pkt, 0, sizeof(packet));
pkt->icmp_type = ICMP_ECHO;
pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));

我找到了告诉我使用标志 -D__USE_BSD 的答案但它没有用。

有没有人知道:

  1. 如何让这个程序发挥作用?
  2. 如何不使用 <netinet/ip_icmp.h> 编写一个简单的 ping 程序?

最佳答案

在包含 header 之前添加 GNU 扩展的定义:

#define _GNU_SOURCE

或 -D_GNU_SOURCE 标记给编译器。

关于c - 在 ARM 上取消引用指向不完整类型但不是 x86 上的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37922835/

相关文章:

math - 64 位乘法/除法,无需 64 位乘法或除法指令

c++ - C中如何跳转程序执行到特定地址?

c++ - 各种编译器上的 RDRAND 和 RDSEED 内在函数?

c - 防止 gcc 内联函数

c++ - 对 'ClassName::memberField[abi:cxx11]' 的 undefined reference

operating-system - ARM 的 ARM 处理器/操作系统是否有安全环?

c - 有没有办法在运行 Linux 或 Windows 的台式计算机上使用 C 中的 "test"关键字来实现 "volatile"?

c - 十六进制 sha1 输出错误

c - Not null terminated string - 没有可理解原因的 KlocWork 错误

ARM : What's the difference between APCS and AAPCS ABI?