c++ - 对 `DhcpEnumSubnets' 的 undefined reference

标签 c++ winapi dhcp dev-c++

我正在尝试使用 Windows API 从 DHCP 服务器获取一些信息,但我一直收到 undefined reference 。

根据 MSDN DhcpEnumSubnets 在 dhcpsapi.lib 中,我已经验证了 dhcpsapi.h 文件中的原型(prototype) IS 并且(通过简单的文本搜索)它 IS在 .lib 中

正如您在下面看到的,我正在链接库,但我仍然遇到链接器错误。 有人对我有什么想法吗?

这是我的编译日志:我在 Windows XP SP2 上使用 Dev-C++ 4.9.9.2,带有最新的 Windows 平台 SDK

"Microsoft® Windows® Software Development Kit (SDK) for Windows Server 2008 and .NET Framework 3.5"
"This release of the Windows SDK supports x86, x64, and IA64 platforms for building and running applications on Windows XP SP2, Windows Server 2003 R2, Windows Vista, and Windows Server 2008."


<我> 编译器:默认编译器 构建 Makefile:“C:\Projects\dhcptest\Makefile.win” 执行 make clean rm -f main.o dhcptest.exe

g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"-I"C:/Dev-Cpp/include/c++/3.4.2/backward"-I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"-I"C:/Dev-Cpp/include/c++/3.4.2"-I"C :/Dev-Cpp/include"-I"C:/Program Files/Microsoft SDKs/Windows/v6.1/Include"

g++.exe main.o -o "dhcptest.exe"-L"C:/Dev-Cpp/lib"-L"C:/Program Files/Microsoft SDKs/Windows/v6.1/Lib""。 ./../Program Files/Microsoft SDKs/Windows/v6.1/Lib/WS2_32.Lib""../../Program Files/Microsoft SDKs/Windows/v6.1/Lib/dh​​cpsapi.lib

main.o(.text+0x128):main.cpp: 未定义对“DhcpGetVersion”的引用 main.o(.text+0x1d7):main.cpp: 未定义对“DhcpEnumSubnets”的引用 main.o(.text+0x2b2):main.cpp: 未定义对“DhcpEnumSubnetClients”的引用

collect2: ld 返回了 1 个退出状态

make.exe: * [dhcptest.exe] 错误 1

执行终止


编辑: 我通过 impdef/implib-ing dhcpsapi.dll 并链接到该库解决了这个问题。不知道 MS 平台 SDK 中提供的库是怎么回事。

最佳答案

我在您的命令行中看到 -L 选项,它指定了额外的库路径,但我没有看到任何 -l 以指定要链接到的库。

我会尝试以下方法:

g++.exe main.o -o "dhcptest.exe" -L"C:/Dev-Cpp/lib" -L"C:/Program Files/Microsoft SDKs/Windows/v6.1/Lib" -lWS2_32 -ldhcpsapi

关于c++ - 对 `DhcpEnumSubnets' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4322444/

相关文章:

c++ - visual c++ 2008 发布问题

c# - 在 WndProc 中处理 AeroSnap 消息

linux - DHCP 服务器在 DHCP ACK 消息中不包含 NTP 服务器地址

windows - 使用 USB/ETH 连接访问我的嵌入式设备的友好名称

c++ - FFmpeg - 通过管道提供原始帧 - FFmpeg 不检测管道关闭

c++ - 大括号封闭的初始化列表?转换为 vector

C++ 披萨订购程序不确定为什么会发生错误

c++ - std::optional 类的实现

c - 如何通过 UNICODE 表示的名称确保并获取窗口句柄?

ubuntu - 没有分配给旧 Ubuntu Box 的 ip