Article View: comp.unix.programmer
Article #3552static/shared linking with C and C++
From: Anon
Date: Tue, 19 Nov 2002 15:21
Date: Tue, 19 Nov 2002 15:21
24 lines
2415 bytes
2415 bytes
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:
<HFsC9.52551$__1.29668@rwcrnsc51.ops.asp.att.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,68b09b041b067487,start X-Google-Attributes: gid11318c,public X-Google-Thread: fc89c,68b09b041b067487,start X-Google-Attributes: gidfc89c,public X-Google-ArrivalTime: 2002-11-19 07:21:12 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail From: "@please@no.spam" <""ddrav\"@please@no.spam"> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.unix.programmer,gnu.gcc.help Subject: static/shared linking with C and C++ Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 25 Message-ID: <HFsC9.52551$__1.29668@rwcrnsc51.ops.asp.att.net> NNTP-Posting-Host: 66.31.43.190 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc51.ops.asp.att.net 1037719271 66.31.43.190 (Tue, 19 Nov 2002 15:21:11 GMT) NNTP-Posting-Date: Tue, 19 Nov 2002 15:21:11 GMT Organization: AT&T Broadband Date: Tue, 19 Nov 2002 15:21:11 GMT