comp.lang.ada
 help / color / mirror / Atom feed
* Linking an Ada DLL with MSVC++
@ 2002-10-10 20:06 Marc A. Criley
  2002-10-10 20:50 ` Stephen Leake
  2002-10-11 11:21 ` Marc A. Criley
  0 siblings, 2 replies; 3+ messages in thread
From: Marc A. Criley @ 2002-10-10 20:06 UTC (permalink / raw)


I've meticulously followed the instructions in the GNAT User Manual
for building a DLL, along with a Microsoft-style import library (i.e.,
the .lib and .exp files).

(This DLL is going to be linked into an existing MSVC++ application,
so it has to be done this way--no COM, no GNU C++, etc.)

I've been able to compile and build everything just fine, but the
linking is failing.

Here's a section from the Ada spec:

   procedure Initialize_Vmf_API;
   pragma Export(C, Initialize_VMF_API, "Initialize_VMF_API");

I build the DLL using gnatdll, build the .def file using dll2def, add
a LIBRARY line to the .def file, and build the import library using
MS's lib utility, all in accordance with the GNAT documentation.`

In the C++ app, I've added vmf_parser_api.lib to the
Project/Settings/Link modules entry.  I have a header file containing
the C function corresponding to the Ada procedure:

	void Initialize_VMF_API();

The header file is wrapped with 'extern "C" {' so as to avoid name
mangling.

But when I finally link, I get a message stating that there is an
"unresolved external symbol _Initialize_VMF_API", i.e., the function
name with a leading underscore.

I tried specifying a link name in the Export pragma having the leading
underscore, but still got the same error.

I've seen postings about other's successful experience linking, but
the postings talking about problems haven't had anything about this
one.

Thanks for any help.

Marc A. Criley



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

* Re: Linking an Ada DLL with MSVC++
  2002-10-10 20:06 Linking an Ada DLL with MSVC++ Marc A. Criley
@ 2002-10-10 20:50 ` Stephen Leake
  2002-10-11 11:21 ` Marc A. Criley
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2002-10-10 20:50 UTC (permalink / raw)


mcq95@earthlink.net (Marc A. Criley) writes:

> I've meticulously followed the instructions in the GNAT User Manual
> for building a DLL, along with a Microsoft-style import library (i.e.,
> the .lib and .exp files).
> 
> <snip>
> 
>    procedure Initialize_Vmf_API;
>    pragma Export(C, Initialize_VMF_API, "Initialize_VMF_API");
> 
> The header file is wrapped with 'extern "C" {' so as to avoid name
> mangling.
> 
> But when I finally link, I get a message stating that there is an
> "unresolved external symbol _Initialize_VMF_API", i.e., the function
> name with a leading underscore.

Back when I was doing this with GNAT 3.12 and Borland C++, I added the
underscore in the external name:

pragma Export (C, Initialize_VMF_API, "_Initialize_VMF_API");

That worked.

There is also the problem of which C calling convention the C++
compiler is using; Cdecl or stdcall. That can influence which link
name it looks for.

-- 
-- Stephe



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

* Re: Linking an Ada DLL with MSVC++
  2002-10-10 20:06 Linking an Ada DLL with MSVC++ Marc A. Criley
  2002-10-10 20:50 ` Stephen Leake
@ 2002-10-11 11:21 ` Marc A. Criley
  1 sibling, 0 replies; 3+ messages in thread
From: Marc A. Criley @ 2002-10-11 11:21 UTC (permalink / raw)


"Marc A. Criley" wrote:
> 
> I've meticulously followed the instructions in the GNAT User Manual
> for building a DLL, along with a Microsoft-style import library (i.e.,
> the .lib and .exp files).

  < remainder of my travails snipped>

One would think that in one of the most widely used Integrated
Development Environments in the industry, that the "Currently Selected
Project" for compiling and linking would also be the Currently Selected
Project when opening the project settings dialog.

One would be mistaken.

Adding the .lib specification to the correct project module entry list
made everything work just fine.

Marc A. Criley



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

end of thread, other threads:[~2002-10-11 11:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-10 20:06 Linking an Ada DLL with MSVC++ Marc A. Criley
2002-10-10 20:50 ` Stephen Leake
2002-10-11 11:21 ` Marc A. Criley

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