SAN Adventures

pageicon Sunday Jun 21, 2009

Building DLLs using Cygwin

I was going through JNI which i required for writing agents for JVMTI. JNI requires the native implementation to be compiled in to the native library, DLL in this case as i was running on Windows using Cygwin. I was searching a bit for creating DLLs for the C implementation  and found this useful link here. The lnik has lot more information about building and using the DLLs. I thought of sharing on this post the building DLL part alone. Suppose i have the following C program:

//HelloPerson.c

#include<stdio.h>
int main(){
    char name[50];
    printf("Enter Your Name\n");
    gets(name);
    printf("Hello, %s!!",name);
    return 0;
}

Use:

gcc-3 -c HelloPerson.c 

to create the Object file. I am using the latest build of Cygwin and it uses gcc-3 command.

After creating the object file we will have to generate the shared library which can be done using:

gcc-3 -shared -o HelloPerson.dll HelloPerson.o

Thats it. We have our required DLL.

 Source: Building and Using DLLs.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed