comp.lang.ada
 help / color / mirror / Atom feed
* Calling Custom C Functions From Ada
@ 2001-08-21 20:57 Brant
  2001-08-21 21:22 ` Ted Dennison
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Brant @ 2001-08-21 20:57 UTC (permalink / raw)


Hi Gang,

I'm trying to call a custom C function from an Ada program.  I've set
my Ada program up using the INTERFACE pragma, but I can't seem to get
the linker to locate the associated C object code.

I've written and built my C functions using Microsoft Visual C++; I've
tried both static and dynamic libraries, so I get the *.lib, *.obj
files along with a *.exp file.  I'm using a DDC-I DACS Ada compiler
under Windows NT.

When I link my Ada code, which one of the generated C files do I need
to reference?  No matter which I choose I get an "adalink: undefined
reference to `MyFunction'" error, which is the same error I get when I
don't even point to a file.  Do I need to do some tweaking of the C
files?  Do I need to reference the specific function (as opposed to
just a file) when I link?

Any help would be greatly appreciated!
Thanks,
Brant



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling Custom C Functions From Ada
  2001-08-21 20:57 Brant
@ 2001-08-21 21:22 ` Ted Dennison
  2001-08-21 21:23 ` Larry Hazel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ted Dennison @ 2001-08-21 21:22 UTC (permalink / raw)


In article <8e205e9b.0108211257.4c56b7d9@posting.google.com>, Brant says...
>I've written and built my C functions using Microsoft Visual C++; I've
>tried both static and dynamic libraries, so I get the *.lib, *.obj
>files along with a *.exp file.  I'm using a DDC-I DACS Ada compiler
>under Windows NT.

Does that compiler not have a section in its manual covering this issue?

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling Custom C Functions From Ada
  2001-08-21 20:57 Brant
  2001-08-21 21:22 ` Ted Dennison
@ 2001-08-21 21:23 ` Larry Hazel
  2001-08-22  2:01 ` Warren W. Gay VE3WWG
  2001-08-22 16:45 ` Brant
  3 siblings, 0 replies; 6+ messages in thread
From: Larry Hazel @ 2001-08-21 21:23 UTC (permalink / raw)


Brant wrote:
> 
> Hi Gang,
> 
> I'm trying to call a custom C function from an Ada program.  I've set
> my Ada program up using the INTERFACE pragma, but I can't seem to get
> the linker to locate the associated C object code.
> 
> I've written and built my C functions using Microsoft Visual C++; I've
> tried both static and dynamic libraries, so I get the *.lib, *.obj
> files along with a *.exp file.  I'm using a DDC-I DACS Ada compiler
> under Windows NT.
> 
> When I link my Ada code, which one of the generated C files do I need
> to reference?  No matter which I choose I get an "adalink: undefined
> reference to `MyFunction'" error, which is the same error I get when I
> don't even point to a file.  Do I need to do some tweaking of the C
> files?  Do I need to reference the specific function (as opposed to
> just a file) when I link?
> 
> Any help would be greatly appreciated!
> Thanks,
> Brant

IIRC, the C compiler mangles the name, so you must reference "_MyFunction" or
something.  I'm not sure if the name mangling is the same for different C
compilers.

Larry
-- 
Larry Hazel
480 West Point Loop
Somerville, AL 35670-5533



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Calling Custom C Functions From Ada
@ 2001-08-21 22:17 Beard, Frank
  0 siblings, 0 replies; 6+ messages in thread
From: Beard, Frank @ 2001-08-21 22:17 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

If you have access to the DUMPBIN.exe then you can 
run it against the DLL, LIB, etc.  It's part of the 
VC++ installation, but Aonix supplied it in the
<ObjectAda>\bin directory.  Maybe DDC-I does as well.
For DLLs the command is (run from DOS console):

    dumpbin /EXPORTS my.dll

It shows you the names by which the routines have been
exported.  I don't remember which option works on LIB and
OBJ files.  "DUMPBIN /ALL my.lib" will show you everything,
but it will be quite a bit of info.  "DUMPBIN /?" will
show you the list of options.

Hope this helps.
Frank

-----Original Message-----
From: Larry Hazel [mailto:lhazel@mindspring.com]
Sent: Tuesday, August 21, 2001 5:24 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Calling Custom C Functions From Ada


Brant wrote:
> 
> Hi Gang,
> 
> I'm trying to call a custom C function from an Ada program.  I've set
> my Ada program up using the INTERFACE pragma, but I can't seem to get
> the linker to locate the associated C object code.
> 
> I've written and built my C functions using Microsoft Visual C++; I've
> tried both static and dynamic libraries, so I get the *.lib, *.obj
> files along with a *.exp file.  I'm using a DDC-I DACS Ada compiler
> under Windows NT.
> 
> When I link my Ada code, which one of the generated C files do I need
> to reference?  No matter which I choose I get an "adalink: undefined
> reference to `MyFunction'" error, which is the same error I get when I
> don't even point to a file.  Do I need to do some tweaking of the C
> files?  Do I need to reference the specific function (as opposed to
> just a file) when I link?
> 
> Any help would be greatly appreciated!
> Thanks,
> Brant

IIRC, the C compiler mangles the name, so you must reference "_MyFunction"
or
something.  I'm not sure if the name mangling is the same for different C
compilers.

Larry
-- 
Larry Hazel
480 West Point Loop
Somerville, AL 35670-5533
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling Custom C Functions From Ada
  2001-08-21 20:57 Brant
  2001-08-21 21:22 ` Ted Dennison
  2001-08-21 21:23 ` Larry Hazel
@ 2001-08-22  2:01 ` Warren W. Gay VE3WWG
  2001-08-22 16:45 ` Brant
  3 siblings, 0 replies; 6+ messages in thread
From: Warren W. Gay VE3WWG @ 2001-08-22  2:01 UTC (permalink / raw)


Brant wrote:
> I'm trying to call a custom C function from an Ada program.  I've set
> my Ada program up using the INTERFACE pragma, but I can't seem to get
> the linker to locate the associated C object code.
> 
> I've written and built my C functions using Microsoft Visual C++; I've
> tried both static and dynamic libraries, so I get the *.lib, *.obj
> files along with a *.exp file.  I'm using a DDC-I DACS Ada compiler
> under Windows NT.
> 
> When I link my Ada code, which one of the generated C files do I need
> to reference?  No matter which I choose I get an "adalink: undefined
> reference to `MyFunction'" error, which is the same error I get when I
> don't even point to a file.  Do I need to do some tweaking of the C
> files?  Do I need to reference the specific function (as opposed to
> just a file) when I link?

If you've not already done so, make sure you compile your C function
with extern "C" linkage. Otherwise the function name get's mangled 
according to C++ mangling conventions:

extern "C" int my_function(void);

or :

extern "C" {

   int my_function(void);

}

-- 
Warren W. Gay VE3WWG
http://members.home.net/ve3wwg



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling Custom C Functions From Ada
  2001-08-21 20:57 Brant
                   ` (2 preceding siblings ...)
  2001-08-22  2:01 ` Warren W. Gay VE3WWG
@ 2001-08-22 16:45 ` Brant
  3 siblings, 0 replies; 6+ messages in thread
From: Brant @ 2001-08-22 16:45 UTC (permalink / raw)


Thanks for your help.  I got it to work.  Indeed "MyFunction" was
exported as "_MyFunction" even with the extern "C" command.  I also
had to link to the .obj file instead of the .lib file.

Thanks again,
Brant



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-08-22 16:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-21 22:17 Calling Custom C Functions From Ada Beard, Frank
  -- strict thread matches above, loose matches on Subject: below --
2001-08-21 20:57 Brant
2001-08-21 21:22 ` Ted Dennison
2001-08-21 21:23 ` Larry Hazel
2001-08-22  2:01 ` Warren W. Gay VE3WWG
2001-08-22 16:45 ` Brant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox