Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
edited by

I have the Go program:

package main

import "C"

//export Getint

func Getint() int {

        return  2

}

func main() {}

and I have generated the .so file with the name t.so and header filet.h`

Now I would like to use the above function in my C program.

So had code but I am not knowing how to execute it.

#include <stdio.h>

#include <t.h>

int main()

{

int a;

a=Getint();

printf("number : %d",a);

return 0;

}

When I execute it using the below command:

gcc c.c t.so

It generates the a.out file

At the time of running the a.out with the command ./a.out it gives an error:

./a.out

Error while loading shared libraries: 

t.so: can not open shared object file: no such file or directory exists.

So I tried with the command:

gcc -c c.c -l t.so

It generates a c.o file and it is not executable.

1 Answer

0 votes
by (36.8k points)

Most probably the loader cannot find a library. Try to put this path to a directory where this library is located to LD_LIBRARY_PATH before running your binary.

export LD_LIBRARY_PATH=/path/to/my/library

./a.out

Want to be a Linux expert? Come and join this Linux course

Do check out the video below

 

Related questions

0 votes
1 answer
asked Dec 1, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 20, 2020 in Linux by blackindya (18.4k points)

Browse Categories

...