使用-std = c99进行编译时,be64toh未链接或被声明

lfx凹槽

当我编译以下程序时(我从C ++中的64位ntohl()获得的所有定义的代码这似乎很明智):

#include <stdint.h>
#if defined(__linux__)
#include <endian.h> //htobe64,be64toh
#include <arpa/inet.h> //ntohs, ntohl, htonl, htons
#elif defined(__FreeBSD__) || defined(__NetBSD__)
#include <sys/endian.h>
#elif defined(__OpenBSD__)
#include <sys/types.h>
#define be16toh(x) betoh16(x)
#define be32toh(x) betoh32(x)
#define be64toh(x) betoh64(x)
#endif

int main()
{
    int64_t i = 0x1212121234343434;
    int64_t j = be64toh(i);
    return 0;
}

使用以下命令进行编译时出现链接错误(我正在运行linux):

gcc -std=c99 endian_test.c -o endian

我收到的错误是:

user@host ~/src/c $ gcc -std=c99 derp.c 
endian_test.c: In function ‘main’:
endian_test.c:17:2: warning: implicit declaration of function ‘be64toh’ [-Wimplicit-function-declaration]
  int64_t j = be64toh(i);
  ^
/tmp/ccYonfH4.o: In function `main':
endian_test.c:(.text+0x23): undefined reference to `be64toh'
collect2: error: ld returned 1 exit status

对我来说,这表明两件事:标头本身已包含在内,但实际上并未包含此功能正常运行所需的函数/宏,因为这意味着编译器希望以后再尝试继续查找该函数,但在尝试时会失败链接。

但是,如果我使用以下命令进行编译(只需删除-std=c99):

gcc endian_test.c -o endian

一切都很顺利,就像黄油一样有效。知道为什么会发生这种情况以及我可以采取什么补救措施吗?对我来说,内核给定的功能(或者我误会为事实?)取决于编译时使用的标准是没有意义的?

提前致谢!

如果没有明确的-std=选项,调用gcc相同-std=gnu89的装置C89 + GNU扩展。GNU扩展将启用宏,这些宏将使您的标头中存在函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当我使用-std = c99时未声明套接字[c]

来自分类Dev

我仅在使用-std = c99时才得到隐式声明错误

来自分类Dev

警告:仅在使用 -std=c99 时隐式声明函数

来自分类Dev

C ++在std :: map <>中使用std :: set <>

来自分类Dev

C ++在std :: map <>中使用std :: set <>

来自分类Dev

std :: find()无法使用gcc进行编译

来自分类Dev

使用std :: map :: at时出错

来自分类Dev

mingw:使用-std = c ++ 11编译时找不到函数

来自分类Dev

在std :: map中使用std :: less无法编译

来自分类Dev

当使用`using namespace std`时std :: isgraph不明确

来自分类Dev

使用std :: vector <std :: string> myString时出错

来自分类Dev

为什么clang抱怨使用带有'-std = c99'标志的可变长度数组?

来自分类Dev

C ++使用std :: string,std :: wstring作为缓冲区

来自分类Dev

使用std :: async c ++ 11返回std:vector

来自分类Dev

在std :: pair中使用`std :: make_pair`:C ++ STL

来自分类Dev

使用新的C ++ 11 std :: async加速std:.vector填充

来自分类Dev

在类中使用std :: vector或std :: list的Visual C ++ 2012

来自分类Dev

使用 std::ostream 和 std::cout 的 C++ 日志记录

来自分类Dev

gsl :: span无法使用std :: regex进行编译

来自分类Dev

在C ++中使用<cstdio>而不是<stdio.h>时,为什么“ std :: printf”和“ printf”都进行编译?

来自分类Dev

使用std :: sort进行拓扑排序

来自分类Dev

使用std :: async从线程进行函数调用?

来自分类Dev

使用std :: move进行矢量构建优化

来自分类Dev

使用std :: is_same进行元编程

来自分类Dev

使用std :: move进行“ take”方法实现

来自分类Dev

使用lambda对std :: map进行排序

来自分类Dev

使用std :: move进行矢量构建优化

来自分类Dev

使用STD对图像进行平滑处理

来自分类Dev

使用std :: move进行无限递归

Related 相关文章

  1. 1

    当我使用-std = c99时未声明套接字[c]

  2. 2

    我仅在使用-std = c99时才得到隐式声明错误

  3. 3

    警告:仅在使用 -std=c99 时隐式声明函数

  4. 4

    C ++在std :: map <>中使用std :: set <>

  5. 5

    C ++在std :: map <>中使用std :: set <>

  6. 6

    std :: find()无法使用gcc进行编译

  7. 7

    使用std :: map :: at时出错

  8. 8

    mingw:使用-std = c ++ 11编译时找不到函数

  9. 9

    在std :: map中使用std :: less无法编译

  10. 10

    当使用`using namespace std`时std :: isgraph不明确

  11. 11

    使用std :: vector <std :: string> myString时出错

  12. 12

    为什么clang抱怨使用带有'-std = c99'标志的可变长度数组?

  13. 13

    C ++使用std :: string,std :: wstring作为缓冲区

  14. 14

    使用std :: async c ++ 11返回std:vector

  15. 15

    在std :: pair中使用`std :: make_pair`:C ++ STL

  16. 16

    使用新的C ++ 11 std :: async加速std:.vector填充

  17. 17

    在类中使用std :: vector或std :: list的Visual C ++ 2012

  18. 18

    使用 std::ostream 和 std::cout 的 C++ 日志记录

  19. 19

    gsl :: span无法使用std :: regex进行编译

  20. 20

    在C ++中使用<cstdio>而不是<stdio.h>时,为什么“ std :: printf”和“ printf”都进行编译?

  21. 21

    使用std :: sort进行拓扑排序

  22. 22

    使用std :: async从线程进行函数调用?

  23. 23

    使用std :: move进行矢量构建优化

  24. 24

    使用std :: is_same进行元编程

  25. 25

    使用std :: move进行“ take”方法实现

  26. 26

    使用lambda对std :: map进行排序

  27. 27

    使用std :: move进行矢量构建优化

  28. 28

    使用STD对图像进行平滑处理

  29. 29

    使用std :: move进行无限递归

热门标签

归档