This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
compiling for shared library
- From: sam lee <skynare at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 11 Jul 2009 10:02:28 -0400
- Subject: compiling for shared library
Hi.
I am trying to create shared library of RtAudio
(http://www.music.mcgill.ca/~gary/rtaudio/).
This is how I compile:
$ g++ -g -Wall -Iinclude -fPIC -D__RTAUDIO_DEBUG__ -DHAVE_GETTIMEOFDAY
-D__LINUX_ALSA__ -c RtAudio.cpp -o RtAudio.o
$ ar ruv librtaudio.a RtAudio.o
$ ranlib librtaudio.a
$ g++ -shared -Wl,-soname,librtaudio.so RtAudio.o -o librtaudio.so
RtAudio.o is 570Kbytes. librtaudio.a is 586KBytes and librtaudio.so is
340KBytes.
Now, I try a demo program that plays saw wave.
$ g++ test.cpp -lrtaudio -lasound -o a.out
$ ldd a.out
....
librtaudio.so => /usr/lib/librtaudio.so (0x00007fdb1de33000)
libasound.so.2 => /usr/lib/libasound.so.2 (0x00007fdb1db4e000)
...
$ ./a.out
No sound is played.
So, I reverse -l order just in case.
$ g++ test.cpp -lasound -lrtaudio -o a.out
$ ldd a.out
...
libasound.so.2 => /usr/lib/libasound.so.2 (0x00007f22e0452000)
librtaudio.so => /usr/lib/librtaudio.so (0x00007f22e0231000)
....
$ ./a.out
No sound is played.
Linking with archive (.a)
$ g++ test.cpp -lasound -l:librtaudio.a
$ ldd a.out
...
libasound.so.2 => /usr/lib/libasound.so.2 (0x00007f3bbce68000)
....
$ ./a.out
Plays sound!
Obviously I am building shared library (librtaudio.so) wrong. Or,
installing it wrong.
Did I miss something?
Thank you.
Sam.