problem compiling with gcc, w32api and libiphlpapi.a

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hello all,

I need a little help.

I am trying to write a program that will allow me to get the MAC address on
a windows machine. I am using cygwin and gcc to build a dll that I can get
the mac address in java JNI.

here is the cpp file:

#include "stdafx.h"
#include <windows.h>
#include <iphlpapi.h>
#include <assert.h>
#include "WindowsMacFinder.h"


// 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)
{
	IP_ADAPTER_INFO AdapterInfo[16];			
	DWORD dwBufLen = sizeof(AdapterInfo);		
// Call GetAdapterInfo
	DWORD dwStatus = GetAdaptersInfo(			
		AdapterInfo,							// [out] buffer to receive data
		&dwBufLen);								// [in] size of receive data buffer
// Verify return value is valid, no buffer overflow
	assert(dwStatus == ERROR_SUCCESS);			
// Contains pointer to current adapter info
	PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
	do {
		PrintMACaddress(pAdapterInfo->Address);	

// Progress through linked list     
		pAdapterInfo = pAdapterInfo->Next;		
	}
	while(pAdapterInfo);						
}

//jni
JNIEXPORT void JNICALL Java_example_jni_WindowsMacFinder_getMACaddress(JNIEnv *, jclass)
{
	GetMACaddress();
}

----

so I try to compile it in the following way:

$bash>gcc -g -v -I"/cygdrive/c/java/jdk1.5.0_08/include"
-I"/cygdrive/c/java/jdk1.5.0_08/include/win32" -I"/cygdrive/c/cygwin/usr/include/w32api" -I"/usr/include/mingw" -Wall -L"/usr/lib/w32api" -L"/usr/lib" -liphlpapi -lnetapi32 -lcap -lws2_32 -ldpnet WindowsMacFinder.cpp

and it cannot find the windows stuff when it compiles:

/cygdrive/c/DOCUME~1/cgraham/LOCALS~1/Temp/cc7KntVs.o: In function
`GetMACaddress':
/cygdrive/c/clay/projects/jnitest/src/c/WindowsMacFinder/WindowsMacFinder.cpp:23: undefined reference to `_GetAdaptersInfo@8'
/cygdrive/c/clay/projects/jnitest/src/c/WindowsMacFinder/WindowsMacFinder.cpp:24: undefined reference to `__assert'
/usr/lib/libcygwin.a(libcmain.o):(.text+0xab): undefined reference to
`_WinMain@16'
collect2: ld returned 1 exit status

weird. I have spent a ton of time making sure the stuff is where its
supposed to be, what am I missing?

Clay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux