测试环境 windowsxp系统, cygwin(gcc 3.4.4)
一。五个源文件
so_test.h, test.c, test_a.c, test_b.c, test_c.c
so_test.h:
#include <stdio.h>
void test_a();
void test_b();
void test_c();
test.c:
#include "so_test.h"
int main(){
test_a();
test_b();
test_c();
}
test_a.c:
#include "so_test.h"
void test_a() {
printf("this is in test_a()\n");
}
test_b.c:
#include "so_test.h"
void test_b(){
printf("this is in test_b()\n");
}
test_c.c:
#include "so_test.h"
void test_c(){
printf("this is in test_c()\n");
}
二.编译
由于是在windows下模拟unix环境,编译过程有些不同,自己按照unix编译测试没有成功。下面的测试是可以的。
gcc -c test_a.c test_b.c test_c.c -o test.o(生成静态库test.o)
gcc -shared -o libtest.dll test.o(生成动态库libtest.dll)
gcc -L./ -ltest -o run test.c(生成可执行文件 run.exe)
三 .在本地其他windows环境中调用失败,在windows环境中调用需要 cygwin库的支持.