您好我有一个用C++编写的程序。当我用g ++编译器在Mac终端中编译它时,它编译并运行。但是当我用g ++编译器在Ubuntu终端中编译相同的C++程序时,它失败了。我不知道为什么会发生。在Ubuntu的C++程序编译失败,但在MacOSX中工作
Ubuntu的g ++编译器版本是4.7.3。
这里是我的代码示例
#include <iostream>
using namespace std;
#define IXSIZE 400
#define IYSIZE 400
#define IZSIZE 3
void putbyte(FILE *outf, unsigned char val)
{
unsigned char buf[1];
buf[0] = val;
fwrite(buf,1,1,outf);
}
void putshort(FILE *outf, unsigned short val)
{
unsigned char buf[2];
buf[0] = (val>>8);
buf[1] = (val>>0);
fwrite(buf,2,1,outf);
}
我获得以下错误
seperate.cpp: In function ‘void putbyte(FILE*, unsigned char)’: seperate.cpp:23:21: error: ‘fwrite’ was not declared in this scope seperate.cpp: In function ‘void putshort(FILE*, short unsigned int)’: seperate.cpp:32:21: error: ‘fwrite’ was not declared in this scope seperate.cpp: In function ‘int putlong(FILE*, long unsigned int)’: seperate.cpp:43:28: error: ‘fwrite’ was not declared in this scope seperate.cpp: In function ‘short unsigned int getshort(FILE*)’: seperate.cpp:49:22: error: ‘fread’ was not declared in this scope seperate.cpp: In function ‘long int getlong(FILE*)’: seperate.cpp:56:22: error: ‘fread’ was not declared in this scope seperate.cpp: In function ‘int main(int, char**)’: seperate.cpp:88:11: error: ‘stderr’ was not declared in this scope seperate.cpp:88:69: error: ‘fprintf’ was not declared in this scope seperate.cpp:89:9: error: ‘exit’ was not declared in this scope seperate.cpp:93:30: error: ‘fopen’ was not declared in this scope seperate.cpp:95:11: error: ‘stderr’ was not declared in this scope seperate.cpp:95:61: error: ‘fprintf’ was not declared in this scope seperate.cpp:96:9: error: ‘exit’ was not declared in this scope seperate.cpp:101:22: error: ‘fgetc’ was not declared in this scope seperate.cpp:114:18: error: ‘SEEK_CUR’ was not declared in this scope seperate.cpp:114:26: error: ‘fseek’ was not declared in this scope seperate.cpp:126:38: error: ‘fread’ was not declared in this scope seperate.cpp:131:12: error: ‘fclose’ was not declared in this scope seperate.cpp:138:25: error: ‘fopen’ was not declared in this scope seperate.cpp:141:11: error: ‘stderr’ was not declared in this scope seperate.cpp:141:54: error: ‘fprintf’ was not declared in this scope seperate.cpp:142:9: error: ‘exit’ was not declared in this scope seperate.cpp:153:36: error: ‘fwrite’ was not declared in this scope seperate.cpp:162:11: error: ‘stderr’ was not declared in this scope seperate.cpp:162:54: error: ‘fprintf’ was not declared in this scope seperate.cpp:163:9: error: ‘exit’ was not declared in this scope seperate.cpp:174:36: error: ‘fwrite’ was not declared in this scope seperate.cpp:183:11: error: ‘stderr’ was not declared in this scope seperate.cpp:183:54: error: ‘fprintf’ was not declared in this scope seperate.cpp:184:9: error: ‘exit’ was not declared in this scope seperate.cpp:195:36: error: ‘fwrite’ was not declared in this scope [email protected]:~/Desktop/abc-master$ g++ -v
代码。我们需要看你的代码。 – jrok
请发布代码。没有它,我们无法为你做任何事;我们不能做任何事情,只能猜测问题可能是什么。 – computerfreaker
请发布一个最小的测试用例,编译器调用和错误。 – juanchopanza