#include <iostream>
extern "C" {
void display(char *msg);
}
hello.cpp:
#include "hello.h"
void display(char* msg) {
std::cerr<<msg<<std::endl;
}
Compile:
gcc -shared hello.cpp -fPIC -o hello.so
Python:
#!/usr/bin/python
#-*- encoding:utf8 -*-
from ctypes import *
test = cdll.LoadLibrary('./hello.so')
test.display('Hello, world')
No comments:
Post a Comment