NIk*_*ket 6 c gcc shared-libraries shared-objects go
我已经浏览了stackoverflow上的所有解决方案以及询问ubuntu.
我有一个去计划
package main
import "C"
//export Getint
func Getint() int {
return 2
}
func main() {}
Run Code Online (Sandbox Code Playgroud)
我已生成.so文件,名称为t.so和头文件th
现在我想在我的C程序中使用这个功能.我编写了代码,但我不知道如何执行它.
#include <stdio.h>
#include <t.h>
int main()
{
int a;
a=Getint();
printf("number : %d",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我执行它时
gcc c.c t.so
Run Code Online (Sandbox Code Playgroud)
它会生成一个.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.
Run Code Online (Sandbox Code Playgroud)
然后我尝试了
gcc -c c.c -l t.so
Run Code Online (Sandbox Code Playgroud)
所以它生成co文件,它不可执行.
很可能您的加载程序找不到库。LD_LIBRARY_PATH在运行二进制文件之前,尝试将路径放在 libarry 所在的目录中。
export LD_LIBRARY_PATH=/path/to/my/library
./a.out
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17715 次 |
| 最近记录: |