I have been provided a dynamic library (.so file) generated in the Linux platform. The file is compiled using the below command.
gcc -c -Wall -Werror -fpic -o factorial.o factorial.c
gcc -shared -o libFactorial.so factorial.o
Now, I have written a C program to call some methods inside the library (.so file) and get the desired output. The dynamic library is kept in the same directory of my C program. I need to link the library with my C program at runtime so that I can debug my C program using Visual Studio Code.
Compiler: gcc
IDE: Visual Studio Code
Platform: Linux
C Program: my_C_Program.c
Dynamic Library : libFactorial.so
When I compile and run my code using the command prompt, I am able to call the methods inside the .so file.
Commands
gcc my_C_Program.c -ldl -o my_C_Program
./my_C_Program -l libFactorial
But when I debug my code using visual studio code, I am getting errors. Do I need to link the library (statically probably ?) with my c program so that it recognizes my library. I don't know how to do that. Do I need to create a MakeFile? If yes, can you please advise how to link a library using that?
Error while debugging:
undefined reference to `dlerror.'
undefined reference to `dlsym.'
undefined reference to `dlerror.'
Please note that I don't have to generate the dynamic library. It is provided by others.