This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: input line is too long


Erik Poupaert wrote:
When I make an objdump of the executable, it says:

SYMBOL TABLE:
[17212](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x000fe73f
_Java_org_eclipse_swt_internal_win32_OS_GetVersionExW@12

When I make an objdump of the jni-dll, it says:

[Ordinal/Name Pointer] Table
	[ 316] _Java_org_eclipse_swt_internal_win32_OS_GetVersionExW@12

The symbols are exactly the same and available in both cases.
Unlike MSVC, the MinGW GCC/binutils toolchain does not export
functions from an EXE, even if you explicitly add
"__declspec(dllexport)" (which is what JNICALL is defined as on
Win32) to the function definition.

The JNI implementation in GCJ ultimately calls the Win32
GetProcAddress( ) function on your EXE to locate the native function
and it fails due to the reason given above - it however
succeeds if the functions are in a DLL.

To make this work with MinGW, here are the steps for a simple
object file (say "foo.o") that exports a function that gets
linked statically into your EXE (say "snafu.exe"):

1. Create an exports definition file:

   dlltool --output-def bar.def foo.o

2. Generate an export file from this:

   dlltool --dllname snafu.exe --output-exp foobar.exp --def bar.def

3. Link in to create the final executable:

   gcc -o snafu.exe foobar.exp foo.o wombat.o

I'm attaching a simple program that you can try out
with and without the above steps to understand the
difference:
--------------------------------- 8< ---------------------------------
#include <stdio.h>
#include <windows.h>

typedef void (*MyFuncPtr)( int);

__declspec(dllexport) void MyCoolFn( int a)
{
    printf( "MyCoolFn: %d\n", a);
}

int main( void)
{
    char strbuf[1024];
    HMODULE hM;

    GetModuleFileName( NULL, strbuf, sizeof(strbuf));

    hM = LoadLibrary( strbuf);

    if( hM == NULL) {
        printf( "LoadLibrary( ) failed!\n");
    }
    else
    {
        MyFuncPtr f = (MyFuncPtr )( GetProcAddress( hM, "MyCoolFn"));

	if( f == NULL)
	{
	    printf( "GetProcAddress( ) failed!\n");
	}
	else
	{
	    (*f)( 333);
	}
    }
    return 0;
}
--------------------------------- 8< ---------------------------------

Hope this helps.

Sincerely Yours,
Ranjit.

--
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]