我遇到了一个编译问题,这些代码来自同一个教授,但是我的同学能够编译它,但我,这就是我试图找出的。
我将 Surface Pro1(intel i5 4G Ram)与 LinuxMint 18.2 64 位操作系统、gcc 版本 5.4.0 一起使用,但我无法使用命令 gcc -m32 ./ch2ex3.c
.这是错误:
fatal error: sys/cdefs.h: No such file or directory, compilation terminated.
但是如果使用相同的命令而不使用选项-m32
工作正常,但它在我的程序末尾给出“段错误”,而它应该打印“NULL”。
问题为什么此选项 -m32
不适用于我的计算机?
这是我使用的代码:
#include <stdio.h>
int *FP; // a global pointer
main(int argc, char *argv[], char *env[])
{
int a,b,c;
printf("enter main: &argc=%x &argv=%x\n", &argc, &argv);
printf("&a=%x &b=%x &c=%x\n", &a, &b, &c);
a=1; b=2; c=3;
A(a,b);
printf("exit main\n");
}
int A(int x, int y)
{
int d,e,f;
printf("enter A\n");
d=4; e=5; f=6;
B(d,e);
printf("exit A\n");
}
int B(int x, int y)
{
int u,v,w;
/////////////////////////////////////////////////////
int *p;
/////////////////////////////////////////////////////
printf("enter B\n");
u=7; v=8; w=9;
/////////////////////////////////////////////////////
p = (int *)&p;
/////////////////////////////////////////////////////
asm("movl %ebp, FP"); // set FP=CPU's %ebp register
/////////////////////////////////////////////////////
printf("FP=%8x p=%8x\n", FP, p);
while(FP)
{
printf("%8x->", FP);
FP = (int *)*FP;
}
printf("NULL\n");
getchar();
/////////////////////////////////////////////////////
printf("exit B\n");
}
最佳答案
我的解决方案是
sudo apt-get install gcc-multilib
如果上述命令在您的 LinuxMint18.2 上不起作用,请转到 Menu -> Administration -> Synaptic Package Manager
,然后搜索关键字 gcc-multilib
和 标记安装
-> 应用。
关于c - 为什么选项 -m32 在我的 Linux 操作系统上不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45911539/