theintencity / py-audio

Python bindings for audio device and speex codecs
GNU Lesser General Public License v3.0
14 stars 8 forks source link

Linking issue with Ubuntu 11.10 from steps provided #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Building project with linux on Ubuntu 11.10 these steps will fail to link 
alsa/other libraries correctly.
================
cannot load audiodev.so and audiospeex.so, please set the PYTHONPATH
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    import audiodev
ImportError: py-audio/audiodev.so: undefined symbol: 
snd_pcm_hw_params_set_channels

Notice no also libs
>ldd audiodev.so 
    linux-vdso.so.1 =>  (0x00007fff5e932000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe379364000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe37905d000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe378e46000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe378aa7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe3797c2000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe378823000)

The hacky fix:
Ubuntu changed default linking behavior, so libraries linked inside of 
libraries you're using won't be linked unless you reference them directly. I'm 
not sure how to get this to work correctly in the setup.py script, but adding 
-Wl,--no-as-needed to the printed g++ calls will fix the problem.

i.e. 
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions 
build/temp.linux-x86_64-2.7/audiodev.o -lpthread -lasound -o 
build/lib.linux-x86_64-2.7/audiodev.so rtaudio-4.0.8/librtaudio.a

becomes:
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions 
-Wl,--no-as-needed build/temp.linux-x86_64-2.7/audiodev.o -lpthread -lasound -o 
build/lib.linux-x86_64-2.7/audiodev.so rtaudio-4.0.8/librtaudio.a

Now we have them:
ldd audiodev.so 
    linux-vdso.so.1 =>  (0x00007fff077ef000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd781bf7000)
    libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007fd78190c000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd781604000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd781380000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd78116a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd780dca000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fd782055000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd780bc6000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd7809be000)

Original issue reported on code.google.com by luke.we...@gmail.com on 27 Jan 2012 at 12:06

GoogleCodeExporter commented 9 years ago
I had a similar error message, except with the audiotts.so library and the 
solution was a bit different.  I had to add asound to the setup.py file.  I 
also had to change the 'libdir' variable.  here is my setup.py file for 
reference:

from distutils.core import setup, Extension
module1 = Extension('audiodev', sources = ['audiodev.cpp'],
                    include_dirs = ['rtaudio-4.0.8'],
                    libraries = ['pthread', 'asound'], extra_link_args = ['rtaudio-4.0.8/librtaudio.a'])
module2 = Extension('audiospeex', sources = ['audiospeex.cpp'],
                    include_dirs = ['speex-1.2rc1/include'],
                    library_dirs = ['speex-1.2rc1/libspeex/.libs'],
                    libraries = ['speex', 'speexdsp'], extra_link_args = ['-fPIC'])
import os
#libdir = 'flite-1.4-release/build/%s-%s%s'%(os.uname()[-1], 
 #                                           os.uname()[0].lower(), os.uname()[2])

libdir = 'flite-1.4-release/build/x86_64-linux-gnu/lib'
print libdir

module3 = Extension('audiotts', sources = ['audiotts.cpp'],
                    include_dirs = ['flite-1.4-release/include'],
                    library_dirs = [libdir],
                    libraries = ['flite_cmu_us_kal', 'flite_cmu_us_awb', 'flite_cmu_us_rms', 
                                 'flite_cmu_us_slt', 'flite_usenglish', 'flite_cmulex', 'flite', 'asound'], #need to add asound?
                    extra_link_args = ['-fPIC'])
setup (name = 'PackageName', version = '1.0',
       description = 'audio device and codecs module',
       ext_modules = [module1, module2, module3])

Original comment by abe.kaze...@gmail.com on 23 Jun 2012 at 12:03

Attachments: