未定义对“strnstr”的引用如何修复它和运行 strnstr
undefined reference to `strnstr' how to fix it and run strnstr
我需要重现 strnstr
函数的行为。我想测试strnstr
但无法编译程序,它写成"implicit declaration of function strnstr [-Wimplicit-function-declaration]"
和"undefined reference to strnstr"
。我包括 header <string.h>
.
我知道 strnstr()
不在标准库中,问题可能与编译器有关,但如何修复它以与 strnstr()
一起使用?
编译版本:gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
标准 C 或 POSIX 中没有名为 strnstr
的函数。它也不在 glibc/Linux 中。
它似乎是 FreeBSD function.
I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?
不确定您为什么认为这是一个编译器问题(除非您认为这是一个编译器固有问题)。如果您的 C 库没有提供它,那么它就是不可用。
因此,如果它在您的系统上不可用(可能您使用的不是 BSD 系统),那么您可以实施它。你可以看一个existing implementation.
我需要重现 strnstr
函数的行为。我想测试strnstr
但无法编译程序,它写成"implicit declaration of function strnstr [-Wimplicit-function-declaration]"
和"undefined reference to strnstr"
。我包括 header <string.h>
.
我知道 strnstr()
不在标准库中,问题可能与编译器有关,但如何修复它以与 strnstr()
一起使用?
编译版本:gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
标准 C 或 POSIX 中没有名为 strnstr
的函数。它也不在 glibc/Linux 中。
它似乎是 FreeBSD function.
I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?
不确定您为什么认为这是一个编译器问题(除非您认为这是一个编译器固有问题)。如果您的 C 库没有提供它,那么它就是不可用。
因此,如果它在您的系统上不可用(可能您使用的不是 BSD 系统),那么您可以实施它。你可以看一个existing implementation.