C interface trouble

Leif Kornstaedt kornstae at ps.uni-sb.de
Fri Feb 1 11:35:03 CET 2002


d.carter at 2020speech.com (David Carter) writes:
> This other code is in a directory I will call "otherstuff". I can use
> it successfully from a standalone C program mymain.c:
> 
> % gcc -mno-cygwin -I../otherstuff/include -c -o mymain.o mymain.c
> % gcc -mno-cygwin -o mymain mymain.o ../otherstuff/obj/*.o
> 
> Next, I wrote myinterface.cc (note: C++ not C) which has an include of
> "mozart.h" as well as one for code that calls the otherstuff. The include
> for the otherstuff, and the calls that use it, are just the same as in
> mymain.c.
> And it compiles fine with
> 
> % oztool c++ -I../otherstuff/include -c myinterface.cc -o myinterface.o
> 
> Now I want to make the DLL. Here's what I tried:
> 
> % oztool ld -o myinterface.so-`oztool platform` ../otherstuff/obj/*.o
> myinterface.o
> 
> The problem is, I get lots of undefined references, generated by calls
> in myinterface.cc to functions in otherstuff.

You `otherstuff' is C code, while `myinterface.cc' is C++ code.
You should make sure that you enclose the C declarations within
an `extern "C"' declaration.  For example (within your
myinterface.cc file):

   extern "C" {
   #include "otherstuff.h"
   }

C++ uses a different name mangling scheme from C, so this
tells the compiler to mangle the names according to the C
convention.

This is just a guess; we might be able to provide more
help if you post a list of the error messages generated by
the `oztool ld' command.

> So - how do I tell "oztool ld" that the calls to in myinterface to
> functions in otherstuff refer to those functions?? One trouble is that
> "oztool ld" with a "-verbose" reveals calls are being made to DLLTOOL
> and DLLWRAP, which I had never heard of before today...

These tools are specific to mingw32 (and cygwin).  They
provide support for building DLLs with gcc.  If you want
to know more about them, I recommend you do a web search ;-)

Hope this helps,
Leif.
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.





More information about the mozart-users mailing list