[Mono-devel-list] Need help with DllImport.

Gary M. Smithrud gary.smithrud at haley.com
Mon Jun 6 09:55:24 EDT 2005


Thank you!  That was indeed the issue (gcc being used on some of the libraries 
that were using C++ code).  The problem, of course, was that other 
applications built with the libraries were appropriate linked, but the 
libraries were not.  Gotta love the fact that gcc can compile C++ code.

Gary.
On Friday 03 June 2005 18:22, Jonathan Pryor wrote:
> On Fri, 2005-06-03 at 09:56 -0400, Gary M. Smithrud wrote:
> > The DLL containing the InitializeKnowledgeBase relies on other shared
> > libraries that are also part of the project and under Mono 1.1.4 I could
> > create a single library that reference the others and it would work then
> > (definitely not ideal).
>
> Sounds like you're improperly linking your library.  When you link your
> library, you should link against all other dependent libraries:
>
> 	$ gcc -shared -out libfoo.so foo.c -ldep1 -ldep2 -ldep3 # ...
>
> A perfect prior example is creating a C++ shared library which uses
> `std::cout` but using `gcc` instead of `g++` to link the .so.  This
> results in libstdc++.so *not* being loaded at runtime, resulting in
> strange library loading errors like you're describing.
>
> The perfect test for this is a small program which dlopen(3)'s your
> library with RTLD_NOW.  If it can be loaded, your library is fine,
> otherwise you have a dependency problem.  (dlerror(3) can be used to
> obtain an error message after a failed attempt loading the library.)
>
> For example:
>
>         /*
>          * dlopen test program for libraries
>          *
>          * Compile as: gcc -o dltest dltest.c -ldl
>          */
>         #include <stdio.h>
>         #include <dlfcn.h>
>
>         int
>         main (int argc, char **argv)
>         {
>                 int i;
>                 for (i = 1; i < argc; ++i) {
>                         void *h;
>                         h = dlopen (argv [i], RTLD_NOW);
>                         if (h == NULL)
>                                 printf ("error loading library `%s': %s",
>         				argv [i], dlerror ());
>                         if (h != NULL)
>                                 dlclose (h);
>                 }
>                 return 0;
>         }
>
> The other thing to keep in mind is that mono translates SIGSEGV into a
> System.NullReferenceException, so it's possible that you're getting a
> null pointer in InitializeKnowledgeBase (perhaps bad structure
> marshaling?), resulting in a SIGSEGV, and hence the
> NullReferenceException.
>
>  - Jon



More information about the Mono-devel-list mailing list