How does one create a dynamic link library in Linux using g++? I searched Google, and I came up with these instructions:
I changed "gcc" to "g++" and ".c" to ".cc". I replaced "something" and "module1" with my library name, "gvector". It created the file libgvector.so.1.0. I wasn't sure where to put it, so I put it in "/usr/local/lib". I added that directory to to my ld.so.conf and ran 'ldconfig' to update my dynamic libraries.
gcc -g -fPIC -c module1.c
gcc -g module1.o -shared -Wl,-soname,libsomething.so.1 -o libsomething.so.1.0
To link against the program, I typed:
g++ hello.cc -lgvector
I got this error:
/usr/bin/ld: cannot find -lgvector
collect2: ld returned 1 exit status
So, I scrounged around in g++'s man page, and found that '-L' should tell it what directory to look in. I tried putting "-L/usr/local/lib" before and after the '-lgvector' switch. Same error.
I scrounged around in g++'s man page some more. That brought me to the "-shared" switch. I tried adding "-shared" at the end of the switch list, and still got the same error. I then tried it in different positions throughout the list, and still go the same error.
Can someone point me to more helpful documentation, or point out my mistake? Thanks!