www.delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2014/07/04/00:14:34

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=u3xm8eEdJUqmVi7faxbmz2ick6U+q976P175rh1FOZM=;
b=y17ipY0fly8hSVQny4y3tVsIMZ7OvMiVR8wdSowiyVIuv1n/RU8krnDKeeLpQAkVeh
3dPmzbZnKI5qb+XqxzzTXPXgmqmgD/CJ1LD3GRRmAkVkfAo07RNJiWTb0wPV4noL8kst
xMMSwS29OT/z9mBujJTt52duu/iGUv4R3aLAKKrKS9uIRU2naHxhKV9SAX1Bp/2IdLsw
9Hfw0gmwNK2qK84tGBlgU377m52Ja8G+EXjSXEODWV7q0OcO73qpdZOLiYpwaPTJ1bzJ
u9UghwmIvhevQAV9KVwKzeY/9zOIqIm9P+yTklIW97wBqTJ+Xfxg3fUiGMntXNz8Xbav
9TWA==
MIME-Version: 1.0
X-Received: by 10.60.83.207 with SMTP id s15mr7574075oey.77.1404447223203;
Thu, 03 Jul 2014 21:13:43 -0700 (PDT)
In-Reply-To: <53B5F51A.1060902@zoot.drehmel.com>
References: <CAFx0xxjWMZp2YBh7OCsqX2GdqWgMdMgvzCDB+0JL2vLhr_SnOg AT mail DOT gmail DOT com>
<53B5E5A2 DOT 6040005 AT buffalo DOT edu>
<53B5F51A DOT 1060902 AT zoot DOT drehmel DOT com>
Date: Thu, 3 Jul 2014 22:13:43 -0600
Message-ID: <CAFx0xxhE0_cSvwncAmRS18gHARTSN1PFG=-rHCAcpmB-sVxzsw@mail.gmail.com>
Subject: Re: [geda-user] VPI and Icarus
From: Dave Williams <dave DOT williams DOT lists AT gmail DOT com>
To: geda-user AT delorie DOT com
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

--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 &quot;name mangling&quot; and you need use the extern =
&quot;C&quot; directive.<br><br></div>I can invoke C functions from the C++=
 app using the extern &quot;C&quot; 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 &quot;ar r&quot; 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 &#39;hello.c&#39; 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 &#39;libvpi.a&#39;=C2=A0 - which=
 I do in the make file.=C2=A0 These errors makes me think my &#39;libvpi.a&=
#39; is not built correctly - the &#39;libvpi.a&#39; file size is only 1102=
 bytes.=C2=A0 But I haven&#39;t found how to rebuild the &#39;libvpi.a&#39;=
 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&#39;m searching =
for info on how to rebuild the VPI library for Icarus. =C2=A0 <br>
<br></div><div>Here&#39;s the rub - I don&#39;t remember if I installed Ica=
rus 0.9.6 from source or with the Linux package manager.=C2=A0 I&#39;ve use=
d Icarus for years and usually I installed from source.=C2=A0 So, there&#39=
;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 &#39;hello&#39; VPI example in Icar=
us - it ran OK when I did not link explicitly to the &#39;libvpi.a&#39; lib=
rary<br>but I used the &#39;iverilog-vpi&#39; binary.=C2=A0 I wonder if &#3=
9;libvpi.a&#39; has been abandoned or is incomplete and VPI support is only=
 in &#39;iverilog-vpi&#39;.=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">&lt;<a href=3D"mailto:robert AT zoot DOT drehmel DOT com" target=
=3D"_blank">robert AT zoot DOT drehmel DOT com</a>&gt;</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>
&gt; 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&quot; function so that it won&#39;t decorate the names.<br>

&gt;<br>
&gt; Alas, I am not sure exactly how to do this. I know that it involves ei=
ther the use of Extern &quot;C&quot; 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&#39;s<b=
r>
customary to wrap the function declarations in the library header(s)<br>
like that:<br>
<br>
&quot;&quot;&quot;<br>
#ifdef __cplusplus<br>
extern &quot;C&quot; {<br>
#endif<br>
<br>
// function declarations<br>
...<br>
<br>
#ifdef __cplusplus<br>
}<br>
#endif<br>
&quot;&quot;&quot;<br>
<br>
Best regards,<br>
Robert<br>
</blockquote></div><br></div>

--089e01184c78d84b0d04fd5659c0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019