未定义的引用`_GetAdaptersAddresses @ 20“ - 但我包括-liphlpapi [英] undefined reference to `_GetAdaptersAddresses@20' - but I included -liphlpapi
问题描述
我用 GCC
在的cygwin
写一些code调用 GetAdaptersAddresses
从 iphlpapi.h
在我的code我设置了 _WIN32_WINNT
以上所要求的 0x0501
并在连接线我已经添加了 -liphlpapi
但链接仍然具有以下失败消息:
GCC -liphlpapi建立/ OBJ / *。Ø-Wall -Wextra -o建立/斌/ asdf.exe的src / asdf.cpp
/tmp/ccdjLPVY.o:asdf.cpp:(.text+0x153):未定义的引用`_GetAdaptersAddresses @ 20'
collect2:劳工处返回1退出状态
从一些片段 asdf.cpp
:
#如果_WIN32_WINNT< 0x0501
指令#warning _WIN32_WINNT设置比0x0501低,固定
和#undef _WIN32_WINNT
#定义_WIN32_WINNT 0x0501
#万一
#包括LT&;&winsock2.h GT;
#包括LT&;&iphlpapi.h GT;
我知道他们的存在实在可恨:
字符串/usr/i686-pc-mingw32/sys-root/mingw/lib/libiphlpapi.a |排序| uniq的| grep的GetAdapters
__imp__GetAdaptersAddresses @ 20
__imp__GetAdaptersInfo @ 8
_GetAdaptersAddresses @ 20
_GetAdaptersInfo @ 8
GetAdaptersAddresses
GetAdaptersInfo$字符串/usr/lib/w32api/libiphlpapi.a |排序| uniq的| grep的GetAdapters
__imp__GetAdaptersAddresses @ 20
__imp__GetAdaptersInfo @ 8
_GetAdaptersAddresses @ 20
_GetAdaptersInfo @ 8
GetAdaptersAddresses
GetAdaptersInfo
有没有人看到我已经错过了?
编辑:答案
#改变顺序,把连接选项最后:
#之前:
GCC编译-liphlpapi / OBJ / *。Ø-Wall -Wextra -o建立/斌/ asdf.exe的src / asdf.cpp
#后:
GCC编译/ OBJ / *。Ø-Wall -Wextra -o建立/斌/ asdf.exe的src / asdf.cpp -liphlpapi
如这个问题的解释,海湾合作委员会论证事项的顺序。您需要将库纳入移动到依赖于它的对象后。
I'm using gcc
under cygwin
to write some code that calls GetAdaptersAddresses
from iphlpapi.h
in my code I've set _WIN32_WINNT
above the required 0x0501
and on the linker line I've added -liphlpapi
but the linker is still failing with the following message:
gcc -liphlpapi build/obj/*.o -Wall -Wextra -o build/bin/asdf.exe src/asdf.cpp
/tmp/ccdjLPVY.o:asdf.cpp:(.text+0x153): undefined reference to `_GetAdaptersAddresses@20'
collect2: ld returned 1 exit status
Some snippets from asdf.cpp
:
#if _WIN32_WINNT < 0x0501
#warning _WIN32_WINNT was set lower than 0x0501, fixing
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <winsock2.h>
#include <iphlpapi.h>
I know they're there darn it:
strings /usr/i686-pc-mingw32/sys-root/mingw/lib/libiphlpapi.a | sort | uniq | grep GetAdapters
__imp__GetAdaptersAddresses@20
__imp__GetAdaptersInfo@8
_GetAdaptersAddresses@20
_GetAdaptersInfo@8
GetAdaptersAddresses
GetAdaptersInfo
$strings /usr/lib/w32api/libiphlpapi.a | sort | uniq | grep GetAdapters
__imp__GetAdaptersAddresses@20
__imp__GetAdaptersInfo@8
_GetAdaptersAddresses@20
_GetAdaptersInfo@8
GetAdaptersAddresses
GetAdaptersInfo
Is anyone seeing what I've missed?
Edit: Answer
# Change the order, put the linker options last:
# Before:
gcc -liphlpapi build/obj/*.o -Wall -Wextra -o build/bin/asdf.exe src/asdf.cpp
# After:
gcc build/obj/*.o -Wall -Wextra -o build/bin/asdf.exe src/asdf.cpp -liphlpapi
As explained in this question, the order of gcc arguments matters. You need to move the library inclusion to after the objects that depend on it.
这篇关于未定义的引用`_GetAdaptersAddresses @ 20“ - 但我包括-liphlpapi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!