stdio.h文件没有 fread(),FILE,fopen(),添加后,编译问题undefined reference to `___stack_base'

chen87yes 2012-10-15 05:58:53
stdio.h文件没有 fread(),FILE,fopen(),添加后,编译问题undefined reference to `___stack_base'
...全文
974 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-10-16
  • 打赏
  • 举报
回复
改用io.h,如果有的话。
Low-level I/O
These functions invoke the operating system directly for lower-level operation than that provided by stream I/O. Low-level input and output calls do not buffer or format data.

Low-level routines can access the standard streams opened at program startup using the following predefined handles:

Stream Handle
stdin 0
stdout 1
stderr 2


Low-level I/O routines set the errno global variable when an error occurs. You must include STDIO.H when you use low-level functions only if your program requires a constant that is defined in STDIO.H, such as the end-of-file indicator (EOF).

Low-Level I/O Functions

Function Use
_close Close file
_commit Flush file to disk
_creat, _wcreat Create file
_dup Return next available file handle for given file
_dup2 Create second handle for given file
_eof Test for end of file
_lseek, _lseeki64 Reposition file pointer to given location
_open, _wopen Open file
_read Read data from file
_sopen, _wsopen Open file for file sharing
_tell, _telli64 Get current file-pointer position
_umask Set file-permission mask
_write Write data to file


_dup and _dup2 are typically used to associate the predefined file handles with different files.
mujiok2003 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]
我看到底层的一些文件和程序里面,有使用 fread()等函数,但是,这些函数用到别的地方就不行了。 各种#include都试过了[/Quote]

使用底层include的文件就行了。
mujiok2003 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]
我看到底层的一些文件和程序里面,有使用 fread()等函数,但是,这些函数用到别的地方就不行了。 各种#include都试过了[/Quote]

使用底层include的文件就行了。
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

引用 10 楼 的回复:
我的板子系统 stdio.h里面没有 fread()等内容,只有printf()等,但标准C stdio.h是有的。于是我在printf();前面添加了fread()原型


只添加原型(申明)没有定义是不性的,说明编译器不支持。看看系统手册,操作系统是不是提供了文件IO,比如read, write等
[/Quote]

我看到底层的一些文件和程序里面,有使用 fread()等函数,但是,这些函数用到别的地方就不行了。 各种#include都试过了
mujiok2003 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
我的板子系统 stdio.h里面没有 fread()等内容,只有printf()等,但标准C stdio.h是有的。于是我在printf();前面添加了fread()原型
[/Quote]

只添加原型(申明)没有定义是不性的,说明编译器不支持。看看系统手册,操作系统是不是提供了文件IO,比如read, write等
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

引用楼主 的回复:
stdio.h文件没有 fread(),FILE,fopen(),添加后,编译问题undefined reference to `___stack_base'


在哪里添加?添加了什么? 不要修改标准库文件
C/C++ code
#include <stdio.h>,
确保include的路径正确。
[/Quote]


我的板子系统 stdio.h里面没有 fread()等内容,只有printf()等,但标准C stdio.h是有的。于是我在printf();前面添加了fread()原型

chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

硬件不支持吧?
[/Quote]

编译信息如下
[LD] Bin_R2_M10_ATV_ZUI_MM_64/AP.elf
/home/mstar/opt/aeon/bin/../lib/gcc/aeon/4.1.2/../../../../aeon/lib/aeonR2/el/libc.a(glue.o): In function `_sbrk':
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:144: undefined reference to `___stack_base'
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:144: undefined reference to `___stack_base'
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:144: undefined reference to `___stack_size'
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:144: undefined reference to `___stack_size'
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:140: undefined reference to `_end'
/home/ahsieh/aeon/build-aeon-gcc-4.1.2/aeon/aeonR2/el/newlib/libc/sys/aeonsim/../../../../../../../../gcc-4.1.2/newlib/libc/sys/aeonsim/glue.c:140: undefined reference to `_end'
collect2: ld returned 1 exit status
make: *** [Bin_R2_M10_ATV_ZUI_MM_64/AP.elf] Error 1
buyong 2012-10-16
  • 打赏
  • 举报
回复
硬件不支持吧?
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

stdio.h文件没有 fread(),FILE,fopen(),

Lz 如何确定的
[/Quote]

标准C stdio.h里面是有 fread(),FILE,fopen()等内容的。 可以在VS src里面打开stdio.h找到原型
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

GCC还是VC?
[/Quote]


GCC
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
我板子的系统 stdio.h文件 只有如下内容,
#ifndef __CHAKRA_STDIO_H__
#define __CHAKRA_STDIO_H__

#include <stdarg.h>
#include <stdlib.h>

#define PRINTF_CHAR_MAX 256

//typedef unsigned long size_t;

#ifdef __cplusplus
extern "C" {
#endif

int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int snprintf(char *str, size_t size, const char *format, ...);
int sprintf(char *str, const char *format, ...) __attribute__ ((deprecated));
int printf(const char *format, ...);
int printk(const char *format, ...);
int putchar(int c);
int puts(const char *s);

int getchar(void);

/* extension */
int kbhit(void);
unsigned int int_sqrt(unsigned int n);
void dump_backtrace(void);
void setconsole(int device_handle);

#ifdef __cplusplus
}
#endif

#endif /* __CHAKRA_STDIO_H__ */


但是我要使用fopen 和fread等函数。添加如下后,就出现 编译问题undefined reference to `___stack_base'

添加内容
#ifndef _FILE_DEFINED

struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
};
typedef struct _iobuf FILE;
#define _FILE_DEFINED
#endif /* _FILE_DEFINED */


//FILE * fopen(const char * path,const char * mode);
FILE * fopen(const char* pathname, const char* type);
int fputc(int _Ch, FILE * _File);
//------------------------------------------------
AnYidan 2012-10-16
  • 打赏
  • 举报
回复
stdio.h文件没有 fread(),FILE,fopen(),

Lz 如何确定的
startservice 2012-10-16
  • 打赏
  • 举报
回复
fopen
语法:
#include <stdio.h>
FILE *fopen( const char *fname, const char *mode );



fopen()函数打开由fname(文件名)指定的文件, 并返回一个关联该文件的流.如果发生错误, fopen()返回NULL. mode(方式)是用于决定文件的用途(例如 用于输入,输出,等等)

Mode(方式) 意义
"r" 打开一个用于读取的文本文件
"w" 创建一个用于写入的文本文件
"a" 附加到一个文本文件
"rb" 打开一个用于读取的二进制文件
"wb" 创建一个用于写入的二进制文件
"ab" 附加到一个二进制文件
"r+" 打开一个用于读/写的文本文件
"w+" 创建一个用于读/写的文本文件
"a+" 打开一个用于读/写的文本文件
"rb+" 打开一个用于读/写的二进制文件
"wb+" 创建一个用于读/写的二进制文件
"ab+" 打开一个用于读/写的二进制文件

示例:

char ch;
FILE *input = fopen( "stuff", "r" );
ch = getc( input );

chen87yes 2012-10-16
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]

改用io.h,如果有的话。
Low-level I/O
These functions invoke the operating system directly for lower-level operation than that provided by stream I/O. Low-level input and output calls do not buffer or format……
[/Quote]

唉,IO里面的 read() write()在俺这个系统也看不到定义,可能是系统软件商 禁用。在底层看到一些read()的调用,但是,都找不到定义的
chen87yes 2012-10-16
  • 打赏
  • 举报
回复
fread()这些函数可能 被禁用了。但是找不到开关啊
armsword 2012-10-15
  • 打赏
  • 举报
回复
GCC还是VC?
mujiok2003 2012-10-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
stdio.h文件没有 fread(),FILE,fopen(),添加后,编译问题undefined reference to `___stack_base'
[/Quote]

在哪里添加?添加了什么? 不要修改标准库文件
#include <stdio.h>, 
确保include的路径正确。

69,371

社区成员

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

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