This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: keep getting "undefined reference to" linker error
- From: Brian Dessent <brian at dessent dot net>
- To: "H.S." <hs dot samix at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 09 Aug 2007 20:41:04 -0700
- Subject: Re: keep getting "undefined reference to" linker error
- References: <f9gm0m$l14$1@sea.gmane.org>
- Reply-to: gcc-help at gcc dot gnu dot org
"H.S." wrote:
> g++ -g -Wall -c -ansi -Wno-deprecated -I./
> -I/home/hs/tmp/taucs/build/linux -I/home/hs/tmp/taucs/src spmat.cc -o
> spmat.o
> g++ spmat.o -o spmat /home/hs/tmp/taucs/lib/linux/libtaucs.a
> -L/home/hs/tmp/taucs/lib/linux -ltaucs
> -L/home/hs/tmp/taucs/external/lib/linux -latlas -llapack -lf77blas
> -lcblas -latlas -lmetis -lm -lg2c
> spmat.o: In function `main':
> /home/hs/tmp/spmat/spmat.cc:15: undefined reference to
> `taucs_ccs_create(int, int, int, int)'
> /home/hs/tmp/spmat/spmat.cc:18: undefined reference to
> `taucs_ccs_free(taucs_ccs_matrix*)'
> collect2: ld returned 1 exit status
> make: *** [spmat] Error 1
I'm guessing that libtaucs is a C library, and there are no 'extern "C"'
qualifiers on the declarations in the taucs.h header. Thus, your
spmat.cc file is compiled as C++ and is trying to call the C++ decorated
versions of these functions, which do not exist. (You can tell this
because in the undefined reference errors the argument signature/types
are present, which you would not see when failing to link a plain C
function. You could double check by looking at the generated assembler
source.)
The proper fix would be to add the standard boilerplate to the header:
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
Brian