This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

linking problem - "undefined reference to ..."


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]