Re: Undefined reference to '...' error under gcc
- From: Chris Croughton <chris@xxxxxxxxxxxx>
- Date: Thu, 26 May 2005 17:58:28 +0100
On 26 May 2005 08:35:32 -0700, siroregano@xxxxxxxxx
<siroregano@xxxxxxxxx> wrote:
> I've got a nice C program written that uses libsndfile (#include
> <sndfile.h>) to convert my raw data into a properly-formatted wav file.
> The program is composed of a single .c file that compiles without error
> under gnu/linux.
>
> Unfortunately, when ld tries to link the file, I get the following:
>
> bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
> wavconvert.c: In function `main':
> wavconvert.c:95: warning: implicit declaration of function `sfclose'
That's a warning from the compilation. Given the names of the other
functions mentioned in errors, and that none of them created warnings,
should it be sf_close?
> /tmp/ccfQdaR8.o(.text+0x149): In function `main':
>: undefined reference to `sf_open'
> /tmp/ccfQdaR8.o(.text+0x1d1): In function `main':
>: undefined reference to `sf_write_int'
> /tmp/ccfQdaR8.o(.text+0x1e9): In function `main':
>: undefined reference to `sf_strerror'
> /tmp/ccfQdaR8.o(.text+0x20c): In function `main':
>: undefined reference to `sfclose'
> collect2: ld returned 1 exit status
Several hints there that it's the linker which is complaining, not the
compiler. /tmp/ccfQdaR8.o gives a clue, it's a .o (object) file not a
..c (C source) file. The references to collect2 and ld are also
indicative.
Linking and libraries are not things which are part of standard C
(linking is mentioned but only in the context of what name formats are
guaranteed to work and be unique).
> I've googled the error, but people only seem to experience it:
> - When using g++, or
> - When using gcc under a gygwin environment
"undefined reference" means that it can't find the function, because you
haven't told the compiler/linker where to look for it. Adding a switch
like -lsndfile may solve it (look at the man pages for details).
One of the Unix programming newsgroups would have more definite
information (I use my own C++ WAV file library, not libsndfile, for WAV
I/O).
Chris C
.
- References:
- Undefined reference to '...' error under gcc
- From: siroregano@xxxxxxxxx
- Undefined reference to '...' error under gcc
- Prev by Date: Re: libs and constants
- Next by Date: Re: abt variable storage like global static,auto ....
- Previous by thread: Re: Undefined reference to '...' error under gcc
- Next by thread: Re: Undefined reference to '...' error under gcc
- Index(es):
Relevant Pages
|
|