c - 在 32 位 Debian Squeeze 下编译的 C 程序导致我 friend 的 64 位程序出现段错误

标签 c linux gcc debian segmentation-fault

不久前,我安装了 Debian,并在 friend 的帮助下配置了它。
昨天我下载了 GCC 4.4,并创建了一个简单的程序来测试它。
这是代码:

#include <stdio.h>

int main () {
    int result;
    printf ("Hello Wor... Linux! This is my %dst program compiled in Debian.\nHow many is 2+2?\n", 1);
    scanf ("%d", &result);
    while (result!=4) {
        printf ("Oh no! You're not going anywhere until you type the correct result! 2+2 is?\n");
        scanf ("%d", &result);
    }
    printf ("Congrats!\n");
    return 0;
}

我通过在 bash 中输入 gcc-4.4 myfile.c 来编译它。然后我尝试运行生成的二进制文件,它的工作正如我想要的那样。然后我将二进制文件发送给我的 friend ,以便也在他的电脑上进行测试。当他尝试运行它时,他收到了段错误消息,并且程序无法运行。
他还使用 Debian,他的内核版本与我的非常相似 (2.6.32-5-686)。唯一的区别是他的内核是 amd-64 内核(他拥有 64 位处理器,而我的是 32 位)。
为什么会发生这种情况?这是否意味着 64 位 Linux 用户将无法运行我的 32 位程序?如果是这样,我可以以一种让他们运行它的方式编译它吗?
请注意,我对 Linux 并没有真正的经验。

最佳答案

他可能需要 chroot。

apt-get install ia32-libs 

应该适用于大多数情况。

请参阅“使用 IA32 chroot 运行 32 位应用程序”http://alioth.debian.org/docman/view.php/30192/21/debian-amd64-howto.html#id292205

关于c - 在 32 位 Debian Squeeze 下编译的 C 程序导致我 friend 的 64 位程序出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4004198/

相关文章:

c - 在 C 客户端-服务器程序中处理超时

php - mysql注入(inject)破坏?

linux - libstdc++.so.6 缺少更高版本的 GLIBCXX 和 CXXABI,无法更新

linux - 由于 “error: cannot compute suffix of object files”,从bash脚本运行./configure失败

c - C FAQ 中引用了哪些书籍?

c - Memcpy 与 memset 耗时相同

linux - 是否有等效于 set wildignore 的方法来忽略带有不可打印字符的文件?

c++ - 为什么 GCC 6 假设数据是 16 字节对齐的?

c - Windows 7 x64 中的 MinGW GCC 不创建可执行文件

Objective-C float 被限制为小数点后 6 位?