gpt4 book ai didi

c++ - 对 `DhcpEnumSubnets' 的 undefined reference

转载 作者:行者123 更新时间:2023-11-28 08:25:08 24 4
gpt4 key购买 nike

我正在尝试使用 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 cleanrm -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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com