Vizible’s Blog

C – Create share library

Posted in Programming by wearetherock on August 21, 2009

1. Code
==================================

// test.c
#include 
static char *name;
void printName(){
	printf("name = %s\n", name);
}
void setName(char *n){
	name = n;
}

~
2. Compile
==================================

> gcc -c test.c -o test.o
> gcc -shared -o libfoo.so test.o

~
3. Test
==================================

>>> from ctypes import cdll
>>> lib = cdll.LoadLibrary('libfoo.so')
>>> lib.setName('java')
27090740
>>> lib.printName()
name = java
12
>>>
Advertisements
Tagged with: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: