Re: keep getting "undefined reference to" linker error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux