I want to create a .so file and let the main.cpp file can call the function where from the .so file.
And these is my files.
//aa.h
#include <stdio.h>
#include <stdlib.h>
void hello();
//hola.c
#include <stdio.h>
#include "aa.h"
void hello()
{printf("Hello world!\n");}
//main.cpp
#include "aa.h"
void hello();
int main(){hello();return 0;}
This is the step below.
Step 1 : Create .so file
$ gcc hola.c -fPIC -shared -o libhola.so
It works
Step 2 : Linking the libhola.so to main.cpp and creating a execution file called test
$ gcc main.cpp -L. -lhola -o test
Just two Step that what I tried.
And the error says:
main.cpp:(.text+0x12): undefined reference to `hello()'
collect2: error: ld returned 1 exit status
I had been tried that move the libhola.so to /usr/lib and move the aa.h to /usr/inclued,but not work.