Article View: comp.unix.programmer
Article #3554Re: static/shared linking with C and C++
From: Andre P. Lemos
Date: Tue, 19 Nov 2002 15:46
Date: Tue, 19 Nov 2002 15:46
54 lines
2972 bytes
2972 bytes
The problem is that you have to put on the header files of your library
the following code before and after the declarations of the functions and
structures:
#ifdef __cplusplus
extern "C"{
#endif
// Declarations of the functions and structures
void f();
void g();
#ifdef _cplusplus
}
#endif
In that way the g++ compiler will known that you are using some C code and
the undefined references will not occour again.
[]' s
Andre Paim Lemos
CS Student - UFMG - Brazil
On Tue, 19 Nov 2002, @please@no.spam wrote:
> My question relates to the complexities of cross-linking object files
> and libraries between C and C++ (specifically gcc and g++) compiled code.
>
> Details: I'm developing a suite of Unix applications. Each app uses at
> least one shared library and at least one executable which links to it.
> I've also got a collection of utility routines in C which are used by
> the entire suite, including the shared libraries.
>
> What I've been doing, and which works quite well, is to compile the
> utility routines into a little static library (libutil.a), making sure
> to compile with -fpic. This way executables can link to it statically,
> which I prefer for simplicity of delivery, and the shared libraries can
> do the same, in which case these symbols become part of the shlib. In
> the latter case I make the utility symbols private to the shlib with a
> version script.
>
> Now I'm trying to add a program written in C++ to the suite. I find that
> if I compile libutil.a with gcc the C++ program can't link with it
> (unresolved references) and if I compile it with g++ the C programs
> can't use it. Do I need to keep two versions around or is there some
> magic switch I'm missing?
>
> Thanks in advance
> DD
>
>
Technical Details
Message-ID:
<Pine.GSO.4.21.0211191340000.6069-100000@turmalina.dcc.ufmg.br>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!news.ticon.net!usenet.pop-mg.rnp.br!news.pop-mg.com.br!turmalina.dcc.ufmg.br!aplReferences:
<HFsC9.52551$__1.29668@rwcrnsc51.ops.asp.att.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,68b09b041b067487 X-Google-Attributes: gid11318c,public X-Google-Thread: fc89c,68b09b041b067487 X-Google-Attributes: gidfc89c,public X-Google-ArrivalTime: 2002-11-19 07:50:18 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!news.ticon.net!usenet.pop-mg.rnp.br!news.pop-mg.com.br!turmalina.dcc.ufmg.br!apl From: "Andre P. Lemos" <apl@dcc.ufmg.br> Newsgroups: comp.unix.programmer,gnu.gcc.help Subject: Re: static/shared linking with C and C++ Date: Tue, 19 Nov 2002 13:46:20 -0200 Organization: POP-MG/RNP Lines: 55 Message-ID: <Pine.GSO.4.21.0211191340000.6069-100000@turmalina.dcc.ufmg.br> References: <HFsC9.52551$__1.29668@rwcrnsc51.ops.asp.att.net> NNTP-Posting-Host: turmalina.dcc.ufmg.br Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: usenet.pop-mg.rnp.br 1037720809 160 150.164.10.1 (19 Nov 2002 15:46:49 GMT) X-Complaints-To: usenet@usenet.pop-mg.rnp.br NNTP-Posting-Date: Tue, 19 Nov 2002 15:46:49 +0000 (UTC) In-Reply-To: <HFsC9.52551$__1.29668@rwcrnsc51.ops.asp.att.net>