I’m new to the .NET / C# world, and I’d like to use fmod ex under Mono (a .NET implementation for Linux).
It appears that mono is able to access C libraries using DllImport, but Fmod for linux is compiled and linked with g++, which seems to be a problem when using mono:

stijn@darkstar Debug $ mono monojockey.exe
Mono-INFO: DllImport loading: ‘libfmodex.so’.
Mono-INFO: DllImport error loading library ‘/usr/local/lib/libfmodex.so: undefined symbol: __cxa_pure_virtual’.

(monojockey.exe:21258): Mono-WARNING **: DllImport unable to load library ‘/usr/local/lib/libfmodex.so: undefined symbol: __cxa_pure_virtual’.

Unhandled Exception: System.DllNotFoundException: libfmodex.so
in (wrapper managed-to-native) FMOD.Factory:FMOD_System_Create (intptr&)

stijn@darkstar Debug $
The __cxa_pure_virtual symbol is defined in libstdc++.so.6, which mono doesn’t access.

I could try to use the windows dll of fmod (which appears to be a native C library, but I can be wrong), but I don’t know if this is possible under linux. Otherwise, I could try to write a .NET wrapper for the needed symbols of libstdc++.so.6, but I heard that mono and C++ libraries don’t play well together.

So I think that a native C version of fmod ex for linux would be the solution to my problem. Could it be possible to release such a version?

  • You must to post comments

Changing all of the C++ code in fmod to C is not going to happen. You can usually C link to the fmod api even though it is compiled with C++, so if it doesnt work under mono then I don’t know what to suggest at this point. Maybe you need to find out how to make that pure_virtual symbol resolve by loading some of the gcc based libraries.

  • You must to post comments

Well, I’ve got it working! :)

The problem is that libfmodex.so doesn’t contain a reference to libstdc++.so.6, whereas every C++ library should have one. This is also the reason why C programs using fmod don’t link when gcc is used instead of g++:

cd ~/fmodapi40420linux/examples/playsound
stijn@darkstar playsound $ gcc -O3 -o playsound main.c ../../api/lib/libfmodex.so -pthread
../../api/lib/libfmodex.so: undefined reference to operator delete(void*)'
../../api/lib/libfmodex.so: undefined reference to
../../api/lib/libfmodex.so: undefined reference to `operator new(unsigned int)’
collect2: ld gaf exit-status 1 terug
stijn@darkstar playsound $ gcc -O3 -o playsound main.c ../../api/lib/libfmodex.so -pthread -lstdc++
stijn@darkstar playsound $ g++ -O3 -o playsound main.c ../../api/lib/libfmodex.so -pthread
stijn@darkstar playsound $

so compiling with gcc works only if you link explicitely with libstdc++ .

I also noticed the problem using ldd:
stijn@darkstar cpptest $ ldd /usr/local/lib/libfmodex.so
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7cd9000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7cd5000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7cb3000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7ca1000)
/lib/ld-linux.so.2 (0x80000000)

Where a self-written dummy C++ library does contain the reference:

stijn@darkstar cpptest $ cat test.cpp

include <iostream>

extern "C" void test();

void test()
std::cout << "Hello world!" << std::endl;
stijn@darkstar cpptest $ g++ -c test.cpp -o test.o
stijn@darkstar cpptest $ g++ test.o -shared -o libtest.so
stijn@darkstar cpptest $ ldd libtest.so
linux-gate.so.1 => (0xffffe000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7e64000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7e42000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e38000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d09000)
/lib/ld-linux.so.2 (0x80000000)

I do not know what is causing the missing reference in libfmodex.so, because I didn’t use any special options to compile my libtest.so library.

Anyway, I can get fmod working under Mono by DllImporting a function from my libtest.so library in my program, so that libstdc++ gets loaded.
I hope you get this issue ironed out, so that fmod can be used in Mono and native C programs without workarounds!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.