From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3420 invoked by alias); 10 Apr 2008 01:14:35 -0000 Received: (qmail 3400 invoked by uid 22791); 10 Apr 2008 01:14:33 -0000 X-Spam-Check-By: sourceware.org Received: from dessent.net (HELO dessent.net) (69.60.119.225) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 10 Apr 2008 01:14:16 +0000 Received: from localhost ([127.0.0.1] helo=dessent.net) by dessent.net with esmtp (Exim 4.50) id 1JjlMk-0006S4-BN; Thu, 10 Apr 2008 01:14:14 +0000 Message-ID: <47FD69FE.837A2DB0@dessent.net> Date: Thu, 10 Apr 2008 01:53:00 -0000 From: Brian Dessent Reply-To: gcc-help@gcc.gnu.org X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: Chris Bouchard CC: gcc-help@gcc.gnu.org Subject: Re: linking problem - "undefined reference to ..." References: <20080409194532.AYL02271@expms3.cites.uiuc.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-04/txt/msg00137.txt.bz2 Chris Bouchard wrote: > I searched the library and found: > -------------------------------------------------------- > [cbouchrd@lx6 ~/tsil-1.1]$ nm -AP libtsil.a | grep ' T ' > [snip other functions] > libtsil.a[initialize.o]: TSIL_SetParameters T 0000030a 00000c6d > [snip other functions] > -------------------------------------------------------- > I see the addition of T 0000030a00000c6d at the end of the function name... is this the name mangling you're talking about? No, those are just the address within the object and the size. The mangled name would look something like "_Z18TSIL_SetParametersP9TSIL_Dataeeeeee". In fact you can see what it is exactly by looking at how g++ encodes the call: g++ -S fig6.cpp -o - | grep TSIL_SetParameters > I did get the library from elsewhere. Is their a way to enforce compatibility? In a sense, yes. C has a much more stable and unchanging ABI, and is callable from C++. So it is much easier to distribute a C library and have it usable by everyone than it is to distribute a C++ library. > Perhaps by forcing compilation by a specific ABI version of gcc using an option I seem to remember reading about... okay I just looked it up... would "-fabi-version=n" fix this? I don't know what the extent of what -fabi-version is able to change, but it's not significant. There's no switch to make a 4.3 gcc ABI compatible with 3.3 gcc for example, nor one to make gcc compatible with the C++ ABI of other vendors' compilers. But that's not relevant here as this is a C library. > >From the website where I downloaded the code, "It is written in C, and can be linked to C/C++ and Fortran applications." So, perhaps I should alter the tsil.h header to declare all extern "C". > > I must admit, I don't know what this means or how to do it but I'll get my books out and start studying. I also don't know what the statement "if __cplusplus is true" means. If you look at some headers for common C libraries you will often see near the top: #ifdef __cplusplus extern "C" { #endif and near the end: #ifdef __cplusplus } #endif The preprocessor symbol __cplusplus is defined when the file is being compiled as C++, and is used to wrap all the declarations with a large "extern "C" { ... }". The reason for the #ifdef is that so it remains a valid C file as well. > 2. maybe the library is a C library and I should declare the functions in tsil.h as extern "C" That or: mv fig6.cpp fig6.c gcc -o fig6 fig6.c -L. -ltsil Brian