Reputation: 218
I'm trying to get some information from the DHCP server using the windows api, but I keep getting undefined references.
According to MSDN DhcpEnumSubnets is in dhcpsapi.lib and I have verified that the prototype IS in the dhcpsapi.h file and (by simple text search) that it IS in the .lib
As you can see below I am linking against the lib, but still I get linker errors. Does someone have any ideas for me ?
Here is my compile log: I'm using Dev-C++ 4.9.9.2 on Windows XP SP2, with the latest Windows Platform 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."
Compiler: Default compiler Building Makefile: "C:\Projects\dhcptest\Makefile.win" Executing 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/dhcpsapi.lib"
main.o(.text+0x128):main.cpp: undefined reference to 'DhcpGetVersion' main.o(.text+0x1d7):main.cpp: undefined reference to 'DhcpEnumSubnets' main.o(.text+0x2b2):main.cpp: undefined reference to 'DhcpEnumSubnetClients'
collect2: ld returned 1 exit status
make.exe: * [dhcptest.exe] Error 1
Execution terminated
Edit: I solved the problem by impdef/implib-ing the dhcpsapi.dll and linking against that library. Have no idea whats up with the lib supplied in the MS Platform SDK.
Upvotes: 0
Views: 451
Reputation: 76815
I'm seeing -L
options in your command-line which specify additional library paths, but I'm not seeing any -l
to specify which library to link against.
I would try the following :
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
Upvotes: 1