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: <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: Subject: Re: [geda-user] VPI and Icarus From: Dave Williams To: geda-user AT delorie DOT com Content-Type: multipart/alternative; boundary=089e01184c78d84b0d04fd5659c0 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 Precedence: bulk --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 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
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.=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
C functions from a C++ application.=C2=A0

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

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

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
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

http:/= /iverilog.wikia.com/wiki/Using_VPI

Thanks for your replies= .

Dave W.



On Thu, Jul 3, 2014 at 6:28 PM, Robert Drehm= el <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. =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.
>
> 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.

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--