Could somebody please help me out, I am confused with command line compilation (C++).
I created a dummy shared library with CodeBlocks and it work ok. Then I tried to use it in an equally dummy application, and that's there that I got my true problem. Shortly, the library is never and by no means seen. First I tried to reach it with CodeBlocks and it never worked in spite of all the attempts. So I decided to purify my experience and tried to link it from the command line.
I looked up the net and found some straightforward guides.
I started with this one
and it was like this:
# Create the executable by linking shared library
gcc -L<path to .SO file> -Wall -o code main.c -l<library name>
# Make shared library available at runtime
export LD_LIBRARY_PATH=<path to .SO file>:$LD_LIBRARY_PATH
# Run executable
./a.out
I never could pass across the very first line, it always explained me that there was no such file or directory.
I am rather new to linux, so I was not sure that I understood it right, so I played a little bit around. I tried to use or not to use angular brackets, to insert or to eliminate spaces before the path and the library name, to bring the library directly to the working directory and thus eliminate using path, to eliminate or not the 'lib' prefix and the library file '.so' extension (that was noticed at another guide, (https://www.ca5.co/code/linux/gcc/gcc-l). I always got the same, either 'cannot find -lMySharedLibrary', or 'MySharedLibrary: no such file or directory.
WHAT - AM - I - DOING - WRONG - ? Please...
I created a dummy shared library with CodeBlocks and it work ok. Then I tried to use it in an equally dummy application, and that's there that I got my true problem. Shortly, the library is never and by no means seen. First I tried to reach it with CodeBlocks and it never worked in spite of all the attempts. So I decided to purify my experience and tried to link it from the command line.
I looked up the net and found some straightforward guides.
I started with this one
How to create shared library (.SO) in C++ (G++)?
To create a shared library in C++ using G++, compile the C++ library code using GCC/ G++ to object file and convert it to shared (.SO) file using gcc/ g++.
iq.opengenus.org
# Create the executable by linking shared library
gcc -L<path to .SO file> -Wall -o code main.c -l<library name>
# Make shared library available at runtime
export LD_LIBRARY_PATH=<path to .SO file>:$LD_LIBRARY_PATH
# Run executable
./a.out
I never could pass across the very first line, it always explained me that there was no such file or directory.
I am rather new to linux, so I was not sure that I understood it right, so I played a little bit around. I tried to use or not to use angular brackets, to insert or to eliminate spaces before the path and the library name, to bring the library directly to the working directory and thus eliminate using path, to eliminate or not the 'lib' prefix and the library file '.so' extension (that was noticed at another guide, (https://www.ca5.co/code/linux/gcc/gcc-l). I always got the same, either 'cannot find -lMySharedLibrary', or 'MySharedLibrary: no such file or directory.
WHAT - AM - I - DOING - WRONG - ? Please...
Last edited: