[Mono-list] P/Invoke on amd64

James Fitzsimons james.fitzsimons@gmail.com
Mon, 14 Feb 2005 22:15:48 +0000


--=-ZX/4Cm5em1bDaENBTmmm
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hi all,
Sorry to keep replying to myself ;)

Yay!! I have it working.

On Mon, 2005-02-14 at 21:55, James Fitzsimons wrote:
> However now that I am (reasonably) sure that P/Invoke is working
> correctly I still can't use my target library libopencv.so. When trying
> to load it I get the following errors:
> Mono-INFO: DllImport loading: 'libopencv'.
> Mono-INFO: DllImport error loading library '/usr/local/lib/libopencv.so:
> undefined symbol: __gxx_personality_v0'.
>=20
> (CvImage.exe:8000): Mono-WARNING **: DllImport unable to load library
> '/usr/local/lib/libopencv.so: undefined symbol: __gxx_personality_v0'.
>=20
> Unhandled Exception: System.DllNotFoundException: opencv
>=20
> Now, I am aware that this has something to do with libstdc++, and I
> definately have that installed, but I don't know what to try next.
So this is what I did. Previously doing an ldd on libhighgui.so what=20
giving me this:

james@athos src $ ldd /usr/local/lib/libhighgui.so=20
        libXm.so.3 =3D> //usr/lib/libXm.so.3 (0x0000002a95675000)
        libMrm.so.3 =3D> //usr/lib/libMrm.so.3 (0x0000002a95a0a000)
        libUil.so.3 =3D> //usr/lib/libUil.so.3 (0x0000002a95b2e000)
        libpng.so.3 =3D> //usr/lib/libpng.so.3 (0x0000002a95cb5000)
        libjpeg.so.62 =3D> //usr/lib/libjpeg.so.62 (0x0000002a95deb000)
        libz.so.1 =3D> /lib/libz.so.1 (0x0000002a95f33000)
        libtiff.so.3 =3D> //usr/lib/libtiff.so.3 (0x0000002a96046000)
        libavcodec.so =3D> //usr/lib/libavcodec.so (0x0000002a9619a000)
        libm.so.6 =3D> /lib/libm.so.6 (0x0000002a966f8000)
        libc.so.6 =3D> /lib/libc.so.6 (0x0000002a9687e000)
        libXmu.so.6 =3D> /usr/lib/libXmu.so.6 (0x0000002a96aa5000)
        libXt.so.6 =3D> /usr/lib/libXt.so.6 (0x0000002a96bbd000)
        libSM.so.6 =3D> /usr/lib/libSM.so.6 (0x0000002a96d20000)
        libICE.so.6 =3D> /usr/lib/libICE.so.6 (0x0000002a96e2b000)
        libXext.so.6 =3D> /usr/lib/libXext.so.6 (0x0000002a96f46000)
        libXp.so.6 =3D> /usr/lib/libXp.so.6 (0x0000002a97057000)
        libX11.so.6 =3D> /usr/lib/libX11.so.6 (0x0000002a97161000)
        libstdc++.so.5 =3D>
/usr/lib/gcc-lib/x86_64-pc-linux-gnu/3.3.4/libstdc++.so.5
(0x0000002a97342000)
        libgcc_s.so.1 =3D> /lib/libgcc_s.so.1 (0x0000002a9753a000)
        libdl.so.2 =3D> /lib/libdl.so.2 (0x0000002a97645000)
        libmp3lame.so.0 =3D> /usr/lib/libmp3lame.so.0 (0x0000002a97748000)
        libvorbis.so.0 =3D> /usr/lib/libvorbis.so.0 (0x0000002a978de000)
        libvorbisenc.so.2 =3D> /usr/lib/libvorbisenc.so.2
(0x0000002a97a09000)
        libpthread.so.0 =3D> /lib/libpthread.so.0 (0x0000002a97ce7000)
        /lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)
        libogg.so.0 =3D> /usr/lib/libogg.so.0 (0x0000002a97e7d000)

You'll notice there is no reference to libopencv in there. So I hacked
the Make file and added libopencv to the linker step. Now doing ldd
/usr/local/lib/libhihgui.so:
james@athos src $ ldd /usr/local/lib/libhighgui.so=20
        libXm.so.3 =3D> //usr/lib/libXm.so.3 (0x0000002a95675000)
        libMrm.so.3 =3D> //usr/lib/libMrm.so.3 (0x0000002a95a0a000)
        libUil.so.3 =3D> //usr/lib/libUil.so.3 (0x0000002a95b2e000)
        libpng.so.3 =3D> //usr/lib/libpng.so.3 (0x0000002a95cb5000)
        libjpeg.so.62 =3D> //usr/lib/libjpeg.so.62 (0x0000002a95deb000)
        libz.so.1 =3D> /lib/libz.so.1 (0x0000002a95f33000)
        libtiff.so.3 =3D> //usr/lib/libtiff.so.3 (0x0000002a96046000)
        libavcodec.so =3D> //usr/lib/libavcodec.so (0x0000002a9619a000)
        libopencv-0.9.so.5 =3D> /usr/local/lib/libopencv-0.9.so.5
(0x0000002a9646d000)
        libm.so.6 =3D> /lib/libm.so.6 (0x0000002a966f8000)
        libc.so.6 =3D> /lib/libc.so.6 (0x0000002a9687e000)
        libXmu.so.6 =3D> /usr/lib/libXmu.so.6 (0x0000002a96aa5000)
        libXt.so.6 =3D> /usr/lib/libXt.so.6 (0x0000002a96bbd000)
        libSM.so.6 =3D> /usr/lib/libSM.so.6 (0x0000002a96d20000)
        libICE.so.6 =3D> /usr/lib/libICE.so.6 (0x0000002a96e2b000)
        libXext.so.6 =3D> /usr/lib/libXext.so.6 (0x0000002a96f46000)
        libXp.so.6 =3D> /usr/lib/libXp.so.6 (0x0000002a97057000)
        libX11.so.6 =3D> /usr/lib/libX11.so.6 (0x0000002a97161000)
        libstdc++.so.5 =3D>
/usr/lib/gcc-lib/x86_64-pc-linux-gnu/3.3.4/libstdc++.so.5
(0x0000002a97342000)
        libgcc_s.so.1 =3D> /lib/libgcc_s.so.1 (0x0000002a9753a000)
        libdl.so.2 =3D> /lib/libdl.so.2 (0x0000002a97645000)
        libmp3lame.so.0 =3D> /usr/lib/libmp3lame.so.0 (0x0000002a97748000)
        libvorbis.so.0 =3D> /usr/lib/libvorbis.so.0 (0x0000002a978de000)
        libvorbisenc.so.2 =3D> /usr/lib/libvorbisenc.so.2
(0x0000002a97a09000)
        libpthread.so.0 =3D> /lib/libpthread.so.0 (0x0000002a97ce7000)
        /lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)
        libogg.so.0 =3D> /usr/lib/libogg.so.0 (0x0000002a97e7d000)

Hurrah. Ok, that's part of the problem fixed. The real issue was with
libopencv missing a reference to libstdc++. But libhighgui has a
reference to it... so now I made a very subtle change to my program.

public static void Main(string[] args)
{
	Console.WriteLine("CvImage test application");
        Console.WriteLine("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D");

A	CvImage.CvCreateWindow("test", 1);           =20
B       CvImage image =3D new CvImage(new CvSize(100,100), 8, 3);
C=09
	image.CvShowImage("test");

}

I moved the line now in position A from position C. Line A is a call to
a libhighgui method. Line B is an opencv method. Since libstdc++ is
loaded by libhighgui in line A, line B executes fine. A bit of a hack
but hey it works for now!

Sorry about the long post but I am just stoked it works. Thanks so much
to everyone that has helped me over the last couple of days. I've learnt
a lot here and I like that feeling :)

Cheers!
James=20

--=20
It's 5.50 a.m.... Do you know where your stack pointer is ?

--=-ZX/4Cm5em1bDaENBTmmm
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQBCESMUtf4qL6AoafMRAhFUAKCndx6nW59llQ5WZ7lkIMA889IWIACgjLes
IhbfOV0NCT5m4V5ufR8xM6k=
=2DA7
-----END PGP SIGNATURE-----

--=-ZX/4Cm5em1bDaENBTmmm--