gcc下未定义的'...'错误引用 [英] Undefined reference to '...' error under gcc
问题描述
您好 -
我已经编写了一个很好的C程序,它使用libsndfile(#include
< sndfile.h>)进行转换将我的原始数据转换为格式正确的wav文件。
该程序由一个单独的.c文件组成,可以无误编译
在gnu / linux下。
不幸的是,当ld尝试链接文件时,我得到以下内容:
bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
wavconvert.c:在函数`main''中:
wavconvert.c:95:警告:隐式声明函数`sfclose''
/tmp/ccfQdaR8.o(.text+0x149):在函数`main''中:
:对`sf_open''
/tmp/ccfQdaR8.o(.text+0x1d1):在函数main中:
:对`sf_write_int'的未定义引用'
/tmp/ccfQdaR8.o(.text+0x1e9):在函数main中:
:对`sf_strerror'的未定义引用'
/tmp/ccfQdaR8.o (.text + 0x20c):在函数`main''中:
:未定义引用`sfclose''
collect2:ld返回1退出状态
我已经用Google搜索了错误,但人们似乎只能体验到它:
- 使用g ++时,或者
- 在使用gcc时一个gygwin环境
我尝试使用以下文件包含该文件:
#include" /usr/include/sndfile.h"
....而不是标准包含,但这并没有改变ld'的
行为。我已经确认该文件确实存在,并且确实将
引用到预期存在的.so库。
有谁知道是什么我可能会做些什么来缓解这种情况?
谢谢,
Dave
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(.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
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
推荐答案
si********@gmail.com < si *** *****@gmail.com>写道:
si********@gmail.com <si********@gmail.com> wrote:
我已经编写了一个很好的C程序,它使用libsndfile(#include
< sndfile.h>)将原始数据转换为格式正确的wav文件。
该程序由一个单独的.c文件组成,可以在gnu / linux下无错误地编译。
不幸的是,当ld尝试链接文件时,我得到以下内容:
这不是关于语言C的问题,而是关于
的更多信息
如何让链接器创建一个可执行文件,使其有点偏离 -
这里的主题...
< OT>
bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
看起来你错过了一个命令行参数告诉gcc
你想要链接libsndfile.so。尝试附加-lsndfile
你的命令行,如果你正确安装了库
,它应该可以工作。
wavconvert.c:在函数`main''中:
wavconvert.c:95:警告:隐式声明函数`sfclose''
/tmp/ccfQdaR8.o(.text+0x149):在函数`main''中:
:undefined引用`sf_open''
/tmp/ccfQdaR8.o(.text+0x1d1):在函数`main'':
:未定义引用`sf_write_int''
/ tmp / ccfQdaR8 .o(。text + 0x1e9):在函数main中:
:未定义引用`sf_strerror''
/tmp/ccfQdaR8.o(.text+0x20c):在函数`main'中':
:未定义引用`sfclose''
collect2:ld返回1退出状态
我已经搜索了错误,但人们似乎只是遇到了它:
- 使用g ++时,或者
- 在gygwin环境下使用gcc时
< / OT>
我试过包含文件使用:
#include" /usr/include/sndfile.h" ;
...而不是标准的包含,但这并没有改变ld'的行为。我已经确认该文件确实在那里,并且确实将
引用到预期存在的.so库。
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(.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 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.
这些错误不是'与丢失/错误的包含文件相关,它们会在编译时显示
,而不是当链接器试图将编译后的文件和库放在一起时创建最终的可执行文件。
问候,Jens
-
\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de >
\ __________________________ http://www.toerring.de >
si ******** @ gmail.com 写道:
你好 -
我有一个很好的C程序编写,使用libsndfile(#include
< sndfile.h>)进行转换我的原始数据正确 - 格式化的wav文件。
该程序由一个单独的.c文件组成,在gnu / linux下编译没有错误。
不幸的是,当ld尝试链接文件时,我获取以下内容:
链接器错误不在此处;这是一个C *语言*新闻组。
bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
wavconvert.c:在函数main中:
wavconvert.c:95:警告:隐式声明函数`sfclose''
/tmp/ccfQdaR8.o(.text+0x149):在函数`main''中:
:未定义引用`sf_open''
/tmp/ccfQdaR8.o(.text+0x1d1):In函数`main'':
:未定义引用`sf_write_int''
/tmp/ccfQdaR8.o(.text+0x1e9):函数`main'':
:undefined reference to `sf_strerror''
/tmp/ccfQdaR8.o(.text+0x20c):在函数`main''中:
:未定义引用`sfclose''
collect2:ld返回1退出状态
我已经搜索了错误,但人们似乎只是体验过它:
- 使用g ++时,或
- 在gygwin环境下使用gcc时>
我已尝试使用以下文件包含该文件:
#include" /usr/include/sndfile.h"
...而不是标准包含,但这并不是''改变ld'的行为。我已经确认该文件确实存在,并确实将
引用到预期存在的.so库。
有谁知道我可以做些什么来缓解这个问题?
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(.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
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?
是的。将您的问题发布到新闻:comp.unix.programmer,它将是
主题 - 并且无疑会得到及时回答。
[提示:您需要在库中链接 - 或者,更具体地说,您需要告诉链接器您要链接的库是什么。看看gcc
文档,看看如何。]
HTH,
--ag
>
-
Artie Gold - 德克萨斯州奥斯汀
http://it-matters.blogspot.com (新帖子12/5)
http://www.cafepress.com/goldsays
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
对OT帖子感到抱歉 - 我想我是对于整个C
编程的事情,我还没有将这两者区分开来!
希望你的建议能解决问题;也许makefile在这一点上开始使用是件好事。无论如何,谢谢,我会
把这个问题带到更适合的地方!
Dave
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
这篇关于gcc下未定义的'...'错误引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!