public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Chris Bouchard <cbouchrd@uiuc.edu>
To: gcc-help@gcc.gnu.org
Subject: linking problem - "undefined reference to  ..."
Date: Wed, 09 Apr 2008 22:07:00 -0000	[thread overview]
Message-ID: <20080409145735.AYK68876@expms3.cites.uiuc.edu> (raw)

All,

I'm getting the "undefined reference to ..." error, where ellipses represent any function I attempt to use that is, I believe at least partially, defined within an archived library file.  

Based on my Google research and gcc reference book, I think I'm improperly linking to the library file.  However, I'm unable to locate my mistake.  Any assistance would be greatly appreciated.  

Here's the nitty gritty, with "screen captures" between the dashed lines:

My version of gcc is:
---------------------------------------------------------
[cbouchrd@lx6 ~/tsil-1.1]$ gcc --version
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-8)
[snip]
---------------------------------------------------------

The library file (libtsil.a) resides in the same directory as the c++ file (fig6.cpp):
---------------------------------------------------------
[cbouchrd@lx6 ~/tsil-1.1]$ ls libtsil.a fig6.cpp
fig6.cpp  libtsil.a
---------------------------------------------------------

The c++ file looks like this (simplest form to illustrate  problem):
---------------------------------------------------------
#include "/home/theorist/cbouchrd/local/include/tsil.h"
int main () {
  TSIL_DATA foo;
  TSIL_REAL x,y,z,u,v,s,qq;
  TSIL_SetParameters (&foo,x,y,z,u,v,qq);
  return 0;
}
---------------------------------------------------------
where the data types TSIL_DATA and TSIL_REAL are defined in the header file (tsil.h).

My invocation of gcc goes like this:
---------------------------------------------------------
[cbouchrd@lx6 ~/tsil-1.1]$ g++ -t -o fig6.exe fig6.cpp -L. -ltsil
---------------------------------------------------------
where I think I'm telling gcc to go to the working directory to look for library files (-L.) and then to link to libtsil.a (-ltsil). 

The subsequent error message and associated info due to the -t flag is:
---------------------------------------------------------
/tmp/ccp26z8w.o(.text+0x96): In function `main':
: undefined reference to `TSIL_SetParameters(TSIL_Data*, long double, long double, long double, long double, long double, long double)'
/usr/bin/ld: link errors found, deleting executable `fig6.exe'
/usr/bin/ld: mode elf_i386
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crt1.o
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crti.o
/usr/lib/gcc/i386-redhat-linux/3.4.6/crtbegin.o
/tmp/ccp26z8w.o
-lstdc++_shared (/usr/lib/gcc/i386-redhat-linux/3.4.6/libstdc++_shared.so)
-lm (/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../libm.so)
-lgcc_s (/usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_s.so)
/lib/libc.so.6
(/usr/lib/libc_nonshared.a)elf-init.oS
-lgcc_s (/usr/lib/gcc/i386-redhat-linux/3.4.6/libgcc_s.so)
/usr/lib/gcc/i386-redhat-linux/3.4.6/crtend.o
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crtn.o
collect2: ld returned 1 exit status
---------------------------------------------------------

If there are any pieces of information that I should've provided but didn't please let me know... I'm a bit of a newbie.

Thanks,
Chris Bouchard

             reply	other threads:[~2008-04-09 19:58 UTC|newest]

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

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=20080409145735.AYK68876@expms3.cites.uiuc.edu \
    --to=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).