Hi, i am trying to compile a simple program that returns the users mac adress. The problem is that I get this error message when compiling it :
[Linker error] undefined reference to `_imp__UuidCreateSequential@4'
What can be the reason for this?
Thank you!!
Tom
// GetMACUuid.cpp : Defines the entry point for the console application.
//
// Author: Khalid Shaikh [Shake@ShakeNet.com]
// Date: April 5th, 2002
//
// This program fetches the MAC address of the localhost by creating a UUID
// and obtaining the IP address through that
//
// Prewindows 2000 one should replace the function below
// UuidCreateSequential with UuidCreate
// Microsoft decided that it was not wise to put the MAC address in the UUID
// hence changed the algorithm in Windows 2000 and later to not include it.
//
// Supported in Windows NT/2000/XP
// Supported in Windows 95/98/Me
//
// Supports single NIC card.
include "stdafx.h"
include <Windows.h>
include <rpc.h>
include <rpcdce.h>
pragma comment(lib, "rpcrt4.lib")
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[6];
UUID uuid;
UuidCreateSequential( &uuid ); // Ask OS to create UUID
for (int i=2; i<8; i++) // Bytes 2 through 7 inclusive are MAC address
MACData[i - 2] = uuid.Data4[i];
PrintMACaddress(MACData); // Print MAC address
}
int _tmain(int argc, _TCHAR* argv[])
{
GetMACaddress(); // Obtain MAC address of adapters
return 0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2006-05-10
You cannot link with the PSDK export library, it is not of a format compatible with MinGW/GCC. The documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuidcreatesequential.asp), says to link Rpcrt4.lib; GNU uses a different naming convention (lib prefix, .a extension) so the export library you require is libRpcrt4.a. As this is in the default library path it can be linked with the linker option -lRpcrt. You should also use the MinGW implementations of rpc.h and rpcdce.h rather than the PSDK versions in order to avoid any possible licensing and compatibility issues.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c ../tump/GetMACUUID.cpp -o ../tump/GetMACUUID.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 Platform SDK for Windows XP SP2/Include"
g++.exe ../tump/GetMACUUID.o ../tump/stdafx.o -o "macadress.exe" -L"C:/Dev-Cpp/lib" -L"C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Lib" "../Program Files/Microsoft Platform SDK for Windows XP SP2/Lib/RpcRT4.Lib"
../tump/GetMACUUID.o(.text+0x6b):GetMACUUID.cpp: undefined reference to `_imp__UuidCreateSequential@4'
collect2: ld returned 1 exit status
make.exe: *** [macadress.exe] Error 1
Execution terminated
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, i am trying to compile a simple program that returns the users mac adress. The problem is that I get this error message when compiling it :
[Linker error] undefined reference to `_imp__UuidCreateSequential@4'
What can be the reason for this?
Thank you!!
// GetMACUuid.cpp : Defines the entry point for the console application.
//
// Author: Khalid Shaikh [Shake@ShakeNet.com]
// Date: April 5th, 2002
//
// This program fetches the MAC address of the localhost by creating a UUID
// and obtaining the IP address through that
//
// Prewindows 2000 one should replace the function below
// UuidCreateSequential with UuidCreate
// Microsoft decided that it was not wise to put the MAC address in the UUID
// hence changed the algorithm in Windows 2000 and later to not include it.
//
// Supported in Windows NT/2000/XP
// Supported in Windows 95/98/Me
//
// Supports single NIC card.
include "stdafx.h"
include <Windows.h>
include <rpc.h>
include <rpcdce.h>
pragma comment(lib, "rpcrt4.lib")
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[6];
}
int _tmain(int argc, _TCHAR* argv[])
{
GetMACaddress(); // Obtain MAC address of adapters
}
You cannot link with the PSDK export library, it is not of a format compatible with MinGW/GCC. The documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuidcreatesequential.asp), says to link Rpcrt4.lib; GNU uses a different naming convention (lib prefix, .a extension) so the export library you require is libRpcrt4.a. As this is in the default library path it can be linked with the linker option -lRpcrt. You should also use the MinGW implementations of rpc.h and rpcdce.h rather than the PSDK versions in order to avoid any possible licensing and compatibility issues.
Clifford
The compile log is:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c ../tump/GetMACUUID.cpp -o ../tump/GetMACUUID.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 Platform SDK for Windows XP SP2/Include"
g++.exe ../tump/GetMACUUID.o ../tump/stdafx.o -o "macadress.exe" -L"C:/Dev-Cpp/lib" -L"C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Lib" "../Program Files/Microsoft Platform SDK for Windows XP SP2/Lib/RpcRT4.Lib"
../tump/GetMACUUID.o(.text+0x6b):GetMACUUID.cpp: undefined reference to `_imp__UuidCreateSequential@4'
collect2: ld returned 1 exit status
make.exe: *** [macadress.exe] Error 1
Execution terminated