[Mono-devel-list] P/Invoke wierdness

James Fitzsimons james.fitzsimons at gmail.com
Sat Feb 12 10:05:03 EST 2005


Hi all,

I am trying to use marshalling to use some C libs from my mono app.
Unfortuately this is not going well. I have to external libraries that I
want to use, libhighgui.so and libopencv.so (from the opencv computer
vision project).

In my application I have the following code:

[DllImport("opencv")]
private static extern IntPtr cvCreateImage( CvSize size, int depth, int
channels ); // used to return IplImage*
		
		
// Highgui stuff	
[DllImport("highgui")]
private static extern System.IntPtr cvLoadImage(string filename, int
iscolor);

public CvImage(string filename, bool isColor)
{	
	Console.WriteLine("Loading image");
	iplImage = cvLoadImage(filename, 1);
	Console.WriteLine("Image loaded");
}
	
public CvImage(CvSize size, int depth, int channels )
{
	iplImage = cvCreateImage( size, depth, channels); 
}


The libraries libhighgui.so and libopencv.so are both in /usr/local/lib.

When I write a small test app that loads an image from file with the
following line:
CvImage image = new CvImage("someimage.jpg", false);

I get the following error:
james at athos src $ mono CvImage.exe 
CvImage test application
=============================
Loading image
mono: symbol lookup error: /usr/local/lib/libhighgui.so: undefined
symbol: cvCreateImage

Which is strange because libhighgui should be calling the cvCreateImage
in libopencv directly...

If I change my application to call the cvCreateImage method in libopencv
directly instead of going via libhighgui like so:
CvImage image = new CvImage(new CvSize(100,100), 8, 3);
I get this:
james at athos src $ mono CvImage.exe 
CvImage test application
=============================

Unhandled Exception: System.DllNotFoundException: opencv
in <0x0004a> (wrapper managed-to-native) Slam.CvImage:cvCreateImage
(Slam.CvSize,int,int)
in <0x00029> Slam.CvImage:.ctor (Slam.CvSize,int,int)
in <0x00062> Slam.MainClass:Main (string[])

Huh? How come it can find libhighgui and not libopencv when they are in
exactly the same location?

I'm confused! Can anyone shed some light?

Cheers,
James Fitzsimons

-- 
It's 5.50 a.m.... Do you know where your stack pointer is ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050212/29f8caf2/attachment.bin 


More information about the Mono-devel-list mailing list