【发布时间】:2016-05-01 17:21:11
【问题描述】:
我已经浏览过 StackOverflow 以及 Ask Ubuntu 上的所有解决方案。
我有一个 Go 程序:
package main
import "C"
//export Getint
func Getint() int {
return 2
}
func main() {}
我已经生成了 .so 文件,名称为 t.so and header filet.h`
现在我想在我的 C 程序中使用这个函数。
我已经写了代码,但我不知道如何执行。
#include <stdio.h>
#include <t.h>
int main()
{
int a;
a=Getint();
printf("number : %d",a);
return 0;
}
当我执行它时
gcc c.c t.so
它生成a.out文件
但在运行 a.out 和 ./a.out 时会出现错误:
./a.out
Error while loading shared libraries: t.so: can not open shared object file: no such file or directory exists.
然后我尝试了:
gcc -c c.c -l t.so
所以它会生成c.o 文件并且它是不可执行的。
【问题讨论】:
-
所有这些文件都在同一个位置
标签: c gcc go shared-libraries shared-objects