473,761 Members | 8,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined reference to '...' error under gcc

Hello-

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'
/tmp/ccfQdaR8.o(.tex t+0x149): In function `main':
: undefined reference to `sf_open'
/tmp/ccfQdaR8.o(.tex t+0x1d1): In function `main':
: undefined reference to `sf_write_int'
/tmp/ccfQdaR8.o(.tex t+0x1e9): In function `main':
: undefined reference to `sf_strerror'
/tmp/ccfQdaR8.o(.tex t+0x20c): In function `main':
: undefined reference to `sfclose'
collect2: ld returned 1 exit status

I've googled the error, but people only seem to experience it:
- When using g++, or
- When using gcc under a gygwin environment

I've tried including the file using:
#include "/usr/include/sndfile.h"
....instead of the standard inclusion, but this doesn't change ld's
behavior. I've verified that the file is indeed there, and does refer
to a .so library that is present where expected.

Does anyone know what I might do to mitigate this?

Thanks,
Dave

Nov 14 '05 #1
10 21106
si********@gmai l.com <si********@gma il.com> 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:
This isn't really a question about the language C but more about
how to get linker to create an executable which makes it a bit off-
topic here...

<OT>
bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
Looks like you're missing a command line argument telling gcc that
you want to link against libsndfile.so. Try appending "-lsndfile" to
your command line and it should work if you installed the library
correctly.
wavconvert.c: In function `main':
wavconvert.c:95 : warning: implicit declaration of function `sfclose'
/tmp/ccfQdaR8.o(.tex t+0x149): In function `main':
: undefined reference to `sf_open'
/tmp/ccfQdaR8.o(.tex t+0x1d1): In function `main':
: undefined reference to `sf_write_int'
/tmp/ccfQdaR8.o(.tex t+0x1e9): In function `main':
: undefined reference to `sf_strerror'
/tmp/ccfQdaR8.o(.tex t+0x20c): In function `main':
: undefined reference to `sfclose'
collect2: ld returned 1 exit status I've googled the error, but people only seem to experience it:
- When using g++, or
- When using gcc under a gygwin environment
</OT>
I've tried including the file using:
#include "/usr/include/sndfile.h"
...instead of the standard inclusion, but this doesn't change ld's
behavior. I've verified that the file is indeed there, and does refer
to a .so library that is present where expected.


These errors aren't related to missing/wrong include files, they would
already show up at compile time, not when the linker is trying to put
together the compiled files and libraries to create the final executable.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #2
si********@gmai l.com wrote:
Hello-

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:
And linker errors are off topic here; this is a C *language* newsgroup.
bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
wavconvert.c: In function `main':
wavconvert.c:95 : warning: implicit declaration of function `sfclose'
/tmp/ccfQdaR8.o(.tex t+0x149): In function `main':
: undefined reference to `sf_open'
/tmp/ccfQdaR8.o(.tex t+0x1d1): In function `main':
: undefined reference to `sf_write_int'
/tmp/ccfQdaR8.o(.tex t+0x1e9): In function `main':
: undefined reference to `sf_strerror'
/tmp/ccfQdaR8.o(.tex t+0x20c): In function `main':
: undefined reference to `sfclose'
collect2: ld returned 1 exit status

I've googled the error, but people only seem to experience it:
- When using g++, or
- When using gcc under a gygwin environment

I've tried including the file using:
#include "/usr/include/sndfile.h"
...instead of the standard inclusion, but this doesn't change ld's
behavior. I've verified that the file is indeed there, and does refer
to a .so library that is present where expected.

Does anyone know what I might do to mitigate this?

Yes. Post your question to news:comp.unix. programmer, where it would be
topical -- and would no doubt be answered promptly.

[hint: You need to link in the library -- or, to be more specific, you
have to tell the linker what library you want to link. Look at the gcc
docs to see how.]

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Nov 14 '05 #3
Sorry about the OT post - I guess I'm new enough to this whole C
programming thing that I had yet to differentiate the two!

Hopefully your advice solves the problem; perhaps a makefile would be a
good thing to start using at this point. At any rate, thanks and I will
take this question somewhere more appropriate!

Dave

Nov 14 '05 #4
On 26 May 2005 08:35:32 -0700, si********@gmai l.com
<si********@gma il.com> 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(.tex t+0x149): In function `main':
: undefined reference to `sf_open'
/tmp/ccfQdaR8.o(.tex t+0x1d1): In function `main':
: undefined reference to `sf_write_int'
/tmp/ccfQdaR8.o(.tex t+0x1e9): In function `main':
: undefined reference to `sf_strerror'
/tmp/ccfQdaR8.o(.tex t+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
Nov 14 '05 #5
"si********@gma il.com" <si********@gma il.com> wrote:
# Sorry about the OT post - I guess I'm new enough to this whole C
# programming thing that I had yet to differentiate the two!

"Assholes do vex me!"
- Robin Williams

# Hopefully your advice solves the problem; perhaps a makefile would be a
# good thing to start using at this point. At any rate, thanks and I will
# take this question somewhere more appropriate!

The #include of the header file is the interface to the library which tells
the compiler how to call the library functions, but it does not instruct
the compiler how to get the library implementation, the actual code that
does the work. That's usually something like -lsndfile on the compiler
command to load /usr/lib/libsndfile.* library implementation with your
code.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Haven't you ever heard the customer is always right?
Nov 14 '05 #6
SM Ryan wrote:
"si********@gma il.com" <si********@gma il.com> wrote:
# Sorry about the OT post - I guess I'm new enough to this whole C
# programming thing that I had yet to differentiate the two!

"Assholes do vex me!"
- Robin Williams


Why insulting people without any reason?
The original poster was very polite, what contrast to your
attitude.

Nov 14 '05 #7
jacob navia <ja***@jacob.re mcomp.fr> wrote:
# SM Ryan wrote:
# > "si********@gma il.com" <si********@gma il.com> wrote:
# > # Sorry about the OT post - I guess I'm new enough to this whole C
# > # programming thing that I had yet to differentiate the two!
# >
# > "Assholes do vex me!"
# > - Robin Williams
# >
#
# Why insulting people without any reason?
# The original poster was very polite, what contrast to your
# attitude.

"The whole &*!@#ing world is against us, Silent Bob."
- Jay

It was the folks of comp.lang.c that pointed Dave to the sound library,
and then when after following their advice he had a further question they
went all lame nimby on him, especially consider how simple the fix was.

Who is insulting whom?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.
Nov 14 '05 #8
ÓÚ Thu, 26 May 2005 08:35:32 -0700£¬si******* *@gmail.comдµ½ £º
Hello-

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'
/tmp/ccfQdaR8.o(.tex t+0x149): In function `main':
: undefined reference to `sf_open'
...

You should link your program with the library correspoding to libsndfile.
Use the following command instead,
gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert -LLIBSNDFILEDIR
-lsndfile
LIBSNDFILEDIR is the directory in which libsndfile.so.* is.

Nov 14 '05 #9

"SM Ryan" <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> wrote

# >
# > "Assholes do vex me!"
# > - Robin Williams
# >

Who is insulting whom?

You're the one who is using the strong language.

Presumably Dave is an American college student who doesn't mind this sort of
thing.
But how do you know that he isn't a Kuwaiti 14-year old, and his father
hasn't forbidden him from reading the ng again because he doesn't want his
son exposed to such language?
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13125
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on Unixware/C++/AT&T componets environment. I have been able to compile all modules after making necessary changes in LINUX/gcc/STL environment. We have two templates defined XList and XMap.
1
3151
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
9612
by: Foolster41 | last post by:
I'm rather new to C++ programing. I'm using the dev-C++ program on a windows XP OS. I'm trying to compile the code for a multi user dungeon (MUD) called circle-mud. When I compile I get the following errors: ---- Compiler: Default compiler Building Makefile: "C:\EvoMud\circle-3.1\src\Makefile.win" Executing make...
4
4162
by: Chris Beall | last post by:
If you want your code to be bulletproof, do you have to explicitly check for the existence of any possibly-undefined variable? Example: window.outerHeight is defined by some browsers, but not others. It would therefore seem prudent, before using this variable, to do something like: if (typeof (window.outerHeight) != "undefined") { do stuff that refers to this variable } else { work around the fact that the variable isn't defined }
1
31187
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no joy. I got dev-c++ and a bit of winsock sample code. I've done nothing out of the ordinary. I could only assume that anyone else that downloaded this software and attempted this would meet with the same result. The problem lies with either the...
17
3348
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
8
18051
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like: undefined symbol yylex. What might have went wrong?
3
11601
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE -DTRACING - D__EXTENSIONS__ -D__RWCOMPILER_H__ -D_REENTRANT -D_RWCONFIG=8s - D_RWCONFIG_12d -D_RWSTDDEBUG -DRWDEBUG -o test1 test1.o -L/lib -
2
6226
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o test test.o libsbml/src/libsbml.la -lsbml -lstdc++ -lm
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.