我已经阅读了StackOverflow和Ask Ubuntu上的所有解决方案。
我有一个Go程序:
package main
import "C"
//export Getint
func Getint() int {
return 2
}
func main() {}
我已经生成了一个名为t.so
和头文件t.h
的.so
文件。
现在我想在我的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
文件,但该文件不可执行。