在线等啊!!C语言里面的fopen问题

walllacecn 2009-04-16 10:41:24
是这样的,由于是windows下面的仿GCC编译环境,开发手机的.我需要读取INI文件,使用fopen(filename,"r")函数,编译时出现m68k-coff/lib/libc.a(filer.o): In function `_open_r':
..../newlib/libc/reent/openr.c:63: undefined reference to `open'
这样的错误.
libc.a是上位机提供的,请问这是什么问题啊?是不是要换个libc.a?我机器上没有,只有c++的libc.lib.

我google了一下.,可我能力有限,明白大意具体怎么弄不明白.第一次开发C程序,我本来是做D的.
还有,只要读取出普通的ANSI的.txt或者ini的内容即可.
/usr/local/m68k-coff/lib/libc.a(sbrkr.o): In function `_sbrk_r':
sbrkr.c:60: undefined reference to `sbrk'
/usr/local/m68k-coff/lib/libc.a(makebuf.o): In function `__smakebuf':
makebuf.c:93: undefined reference to `isatty'
/usr/local/m68k-coff/lib/libc.a(filer.o): In function `_open_r':
filer.c:63: undefined reference to `open'
/usr/local/m68k-coff/lib/libc.a(filer.o): In function `_close_r':
filer.c:100: undefined reference to `close'
/usr/local/m68k-coff/lib/libc.a(filer.o): In function `_lseek_r':
filer.c:142: undefined reference to `lseek'
/usr/local/m68k-coff/lib/libc.a(filer.o): In function `_read_r':
filer.c:184: undefined reference to `read'
/usr/local/m68k-coff/lib/libc.a(filer.o): In function `_write_r':
filer.c:226: undefined reference to `write'
/usr/local/m68k-coff/lib/libc.a(fstatr.o): In function `_fstat_r':
fstatr.c:61: undefined reference to `fstat'


--------------------------------------------------------------------------------

Depending upon the target, system calls are not built into newlib's libc.a. They are too dependent upon the particular target board in use. Libgloss (which comes with newlib net releases) is intended to be the repository of such routines and may either provide them in another library that you must link against or in an object file. For systems that don't have a need for such routines, just stub them out. e.g.


--------------------------------------------------------------------------------

int open (char *f, int flags, ...) { errno = ENOSYS; return -1; }


--------------------------------------------------------------------------------
...全文
835 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
tofu0759 2009-05-03
  • 打赏
  • 举报
回复
顶啊
xiaoshun123 2009-04-29
  • 打赏
  • 举报
回复
帮顶。。。
amossavez 2009-04-29
  • 打赏
  • 举报
回复
我顶楼上的!!
hurricane880 2009-04-29
  • 打赏
  • 举报
回复
楼主还没解决好么?
应用程序在实现时为了和内核交互,就需要系统调用,可以通过库函数完成,也可以自己编写调用函数,那个sbrk其实就是在调用malloc后,会调用的系统函数。下面几个应该是大同小异。比如像open,read,close,create等等,如果是VC的话,就在IO.H里面定义
楼主这里使用libc.a静态链接库。但是这个是newlib中的,而这个newlib是依赖于操作系统的,所以就有以下3种可能:
1.这个库不支持你所在的编译环境,你刚才说的是仿gcc开发,也就是说你所仿真的编译环境压根不支持。
2.你的环境没设置好,其实是支持的。
3.代码有问题,不过看起来这个可能性很小
另外,光有libc.a不行的,还要有相应的函数的头文件。并且编译时要指明,你的stdio.h当中包含了吗?你自己查查里面有没你编译出错未定义的那几个函数。

如果以上方法都不行,就去找Libgloss吧,里面的函数支持了大部分的系统,如果还是不行,就要靠你自己写函数了,对于不用的函数,可以让它直接返回-1就OK,具体的你看看相关的文档说明,都很清楚
caodaxia 2009-04-29
  • 打赏
  • 举报
回复
LZ刚接触C就这么强啊!
向LZ学习。
ies_sweet 2009-04-16
  • 打赏
  • 举报
回复
帮顶了
hurricane880 2009-04-16
  • 打赏
  • 举报
回复
Libgloss
Libgloss is a library for all the details that usually get glossed over. This library refers to things like startup code, and usually I/O support for gcc and C library. The C library used through out this manual is newlib. Newlib is a ANSI conforming C library developed by Cygnus Support. Libgloss could easily be made to support other C libraries, and it can be used standalone as well. The standalone configuration is typically used when bringing up new hardware, or on small systems.

For a long time, these details were part of newlib. This approach worked well when a complete tool chain only had to support one system. A tool chain refers to the series of compiler passes required to produce a binary file that will run on an embedded system. For C, the passes are cpp, gcc, gas, ld. Cpp is the preprocessor, which process all the header files and macros. Gcc is the compiler, which produces assembler from the processed C files. Gas assembles the code into object files, and then ld combines the object files and binds the code to addresses and produces the final executable image.

Most of the time a tool chain does only have to support one target execution environment. An example of this would be a tool chain for the AMD 29k processor family. All of the execution environments for this processor are have the same interface, the same memory map, and the same I/O code. In this case all of the support code is in newlib/sys/FIXME. Libgloss's creation was forced initially be the cpu32 processor family. There are many different execution environments for this line, and they vary wildly. newlib itself has only has a few dependencies that it needs for each target. These are explained later in this doc. The hardware dependent part of newlib was reorganized into a separate directory structure within newlib called the stub dirs. It was initially called this because most of the routines newlib needs for a target were simple stubs that do nothing, but return a value to the application. They only exist so the linker can produce a final executable image. This work was done during the early part of 1993.

After a while it became apparent that this approach of isolating the hardware and systems files together made sense. Around this same time the stub dirs were made to run standalone, mostly so it could also be used to support GDB's remote debugging needs. At this time it was decided to move the stub dirs out of newlib and into it's own separate library so it could be used standalone, and be included in various other GNU tools without having to bring in all of newlib, which is large. The new library is called Libgloss, for Gnu Low-level OS support.


---------上面这个是libgloss的说明
hurricane880 2009-04-16
  • 打赏
  • 举报
回复
9楼讲的蛮清楚的
hurricane880 2009-04-16
  • 打赏
  • 举报
回复
这个问题很明显是编译环境出问题了。N多的函数调用找不到,你没调用那自然是系统调用了,那就是系统级的调用文件你没有。所以自然是编译环境有问题
你是仿GCC编译环境的对把,但是这个地方却提示你说缺少硬件系统所需的核心文件。我去GOOGLE了下,所需要的文件是AIX系统的核心文件。于是呢你在这个环境下打开.INI的时候,要依赖libc.a中的很多命令,但是没有这个文件,所以这个文件所定义的open 啊,close啊,write啊,read啊就会被识别为undefined。
后面所提到的libgloss实际上就是很多提供硬件调用函数的一个库。google一下,里面官方文件说的很明白啊。
思路大概就是这样的。你说的那些东西我都没做过,但是我的分析问题就出在这里。互相学习互相学习```


PS:还是希望大家多看看原理方面的书,搞清楚你每下达一个命令后计算机都做了那些事,而不是把注意力集中在做什么啊,学什么啊,做出来了啊这样很浮躁的感觉。原理懂了,基础扎实,往往学一反三,反之也只能停留在“吃一堑,长一智”这么个不利的情况下。
hndth 2009-04-16
  • 打赏
  • 举报
回复
友情up
walllacecn 2009-04-16
  • 打赏
  • 举报
回复
链接了啊在编译文件里面(GROUP -lg -lm libc.a libcard.a....等几个)


只出现了这个提示:m68k-coff/lib/libc.a(filer.o): In function `_open_r':
..../newlib/libc/reent/openr.c:63: undefined reference to `open'

openr.c不是我编写的C文件,应当是编译器生成的临时文件.


xiaocha 2009-04-16
  • 打赏
  • 举报
回复
newlib 需要操作系统的支持,
如果没有操作系统,需要有和你的板配合的 Libgloss,并链接它
或者你要针对你的板实现没有找到的函数,(未用的的函书可以简单的返回不支持)
sherrik 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ouzhf 的回复:]
不懂,帮顶!
[/Quote]
子晞 2009-04-16
  • 打赏
  • 举报
回复
看看它的api
tian428 2009-04-16
  • 打赏
  • 举报
回复
库没连好
  • 打赏
  • 举报
回复
..../newlib/libc/reent/openr.c:63: undefined reference to `open'

怎么还用了个open,有这个函数的?
coverallwangp 2009-04-16
  • 打赏
  • 举报
回复
连接设置没设置好吧,改一下makefile文件,或者你用的是IDE的话,改改link设置卡
jackyjkchen 2009-04-16
  • 打赏
  • 举报
回复
貌似有很多自编函数没声明,C里面在main前面的不用声明,在main后面的要声明
ouzhf 2009-04-16
  • 打赏
  • 举报
回复
不懂,帮顶!
liliangbao 2009-04-16
  • 打赏
  • 举报
回复
帮顶~
加载更多回复(4)

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧