public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Brian Dessent <brian@dessent.net>
To: Chris Bouchard <cbouchrd@uiuc.edu>
Cc: gcc-help@gcc.gnu.org
Subject: Re: linking problem - "undefined reference  to  ..."
Date: Thu, 10 Apr 2008 01:53:00 -0000	[thread overview]
Message-ID: <47FD69FE.837A2DB0@dessent.net> (raw)
In-Reply-To: <20080409194532.AYL02271@expms3.cites.uiuc.edu>

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

  reply	other threads:[~2008-04-10  1:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-10  1:14 Chris Bouchard
2008-04-10  1:53 ` Brian Dessent [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-04-10  3:24 Chris Bouchard
2008-04-09 22:07 Chris Bouchard
2008-04-10  0:52 ` Brian Dessent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47FD69FE.837A2DB0@dessent.net \
    --to=brian@dessent.net \
    --cc=cbouchrd@uiuc.edu \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).