Mail Archives: geda-user/2014/07/04/00:14:34
--089e01184c78d84b0d04fd5659c0
Content-Type: text/plain; charset=UTF-8
Robert/Steve
Yes C++ does "name mangling" and you need use the extern "C" directive.
I can invoke C functions from the C++ app using the extern "C" directive.
These C functions are built into a static library. The basic steps are -
use gcc to compile the C code to position-independent object code (*.o).
Then create a library from this object code - I use "ar r" to create a
static library. Then use g++ to compile the C++ source and link to the
static library. I could post up the details - but this builds and executes
fine. I can call the
C functions from a C++ application.
But if I try 'hello.c' found in the VPI sample project for Icarus, I get
unresolved type link messages when I try the same build method. The VPI
functions in Icarus are C functions. According to Icarus web info - you
need to link to the library 'libvpi.a' - which I do in the make file.
These errors makes me think my 'libvpi.a' is not built correctly - the
'libvpi.a' file size is only 1102 bytes. But I haven't found how to
rebuild the 'libvpi.a' library only. Guess I could hack the Icarus
Makefile, but I thought that I may have missed something simple - so I'm
searching for info on how to rebuild the VPI library for Icarus.
Here's the rub - I don't remember if I installed Icarus 0.9.6 from source
or with the Linux package manager. I've used Icarus for years and usually
I installed from source. So, there's a chance I could rebuild Icarus and
still have the same problem with the VPI library.
Lastly, when you try the 'hello' VPI example in Icarus - it ran OK when I
did not link explicitly to the 'libvpi.a' library
but I used the 'iverilog-vpi' binary. I wonder if 'libvpi.a' has been
abandoned or is incomplete and VPI support is only in 'iverilog-vpi'.
http://iverilog.wikia.com/wiki/Using_VPI
Thanks for your replies.
Dave W.
On Thu, Jul 3, 2014 at 6:28 PM, Robert Drehmel <robert AT zoot DOT drehmel DOT com>
wrote:
> On 07/04/2014 01:22 AM, Stephen R. Besch wrote:
> > I know of a few solutions. First, and this is really hard and I would
> not recommend it, rewrite the library so it will compile in c++ rather than
> C. Second, write a wrapper library in C++ that calls all the functions in
> C format, or third, tell the C++ compiler that you are calling a "C"
> function so that it won't decorate the names.
> >
> > Alas, I am not sure exactly how to do this. I know that it involves
> either the use of Extern "C" and/or Cdecl, but the exact details for your
> case you will have to look up.
>
> To be able to call C library functions both from C and C++ code, it's
> customary to wrap the function declarations in the library header(s)
> like that:
>
> """
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> // function declarations
> ...
>
> #ifdef __cplusplus
> }
> #endif
> """
>
> Best regards,
> Robert
>
--089e01184c78d84b0d04fd5659c0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div><div><div><div><div><div>Robert/Steve<br><b=
r></div>Yes C++ does "name mangling" and you need use the extern =
"C" directive.<br><br></div>I can invoke C functions from the C++=
app using the extern "C" directive.=C2=A0 These C functions are =
built into a static library.=C2=A0 The basic steps are - use gcc to compile=
the C code to position-independent object code (*.o).=C2=A0 Then create a =
library from this object code=C2=A0 - I use "ar r" to create a st=
atic library.=C2=A0 Then use g++ to compile the C++ source and link to the =
static library.=C2=A0 I could post up the details - but this builds and exe=
cutes fine.=C2=A0=C2=A0 I can call the <br>
C functions from a C++ application.=C2=A0 <br></div></div><div><br></div><d=
iv>But if I try 'hello.c' found in the VPI sample project for Icaru=
s, I get unresolved type link messages when I try the same build method.=C2=
=A0 The VPI functions in Icarus are C functions.=C2=A0 According to Icarus =
web info - you need to link to the library 'libvpi.a'=C2=A0 - which=
I do in the make file.=C2=A0 These errors makes me think my 'libvpi.a&=
#39; is not built correctly - the 'libvpi.a' file size is only 1102=
bytes.=C2=A0 But I haven't found how to rebuild the 'libvpi.a'=
library only.=C2=A0=C2=A0 Guess I could hack the Icarus Makefile, but I th=
ought that I may have missed something simple=C2=A0 - so I'm searching =
for info on how to rebuild the VPI library for Icarus. =C2=A0 <br>
<br></div><div>Here's the rub - I don't remember if I installed Ica=
rus 0.9.6 from source or with the Linux package manager.=C2=A0 I've use=
d Icarus for years and usually I installed from source.=C2=A0 So, there'=
;s a chance I could rebuild Icarus and still have the same problem with the=
VPI library.=C2=A0 <br>
<br></div><div>Lastly, when you try the 'hello' VPI example in Icar=
us - it ran OK when I did not link explicitly to the 'libvpi.a' lib=
rary<br>but I used the 'iverilog-vpi' binary.=C2=A0 I wonder if =
9;libvpi.a' has been abandoned or is incomplete and VPI support is only=
in 'iverilog-vpi'.=C2=A0 <br>
</div></div><br><a href=3D"http://iverilog.wikia.com/wiki/Using_VPI">http:/=
/iverilog.wikia.com/wiki/Using_VPI</a><br><br></div>Thanks for your replies=
. <br><br></div>Dave W. <br><br></div></div><div class=3D"gmail_extra"><br>
<br><div class=3D"gmail_quote">On Thu, Jul 3, 2014 at 6:28 PM, Robert Drehm=
el <span dir=3D"ltr"><<a href=3D"mailto:robert AT zoot DOT drehmel DOT com" target=
=3D"_blank">robert AT zoot DOT drehmel DOT com</a>></span> wrote:<br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex">
<div class=3D"">On 07/04/2014 01:22 AM, Stephen R. Besch wrote:<br>
> I know of a few solutions. First, and this is really hard and I would =
not recommend it, rewrite the library so it will compile in c++ rather than=
C. =C2=A0Second, write a wrapper library in C++ that calls all the functio=
ns in C format, or third, tell the C++ compiler that you are calling a &quo=
t;C" function so that it won't decorate the names.<br>
><br>
> Alas, I am not sure exactly how to do this. I know that it involves ei=
ther the use of Extern "C" and/or Cdecl, but the exact details fo=
r your case you will have to look up.<br>
<br></div>
To be able to call C library functions both from C and C++ code, it's<b=
r>
customary to wrap the function declarations in the library header(s)<br>
like that:<br>
<br>
"""<br>
#ifdef __cplusplus<br>
extern "C" {<br>
#endif<br>
<br>
// function declarations<br>
...<br>
<br>
#ifdef __cplusplus<br>
}<br>
#endif<br>
"""<br>
<br>
Best regards,<br>
Robert<br>
</blockquote></div><br></div>
--089e01184c78d84b0d04fd5659c0--
- Raw text -