ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

无法将UNIX / Linux程序编译为32位程序

2019-09-02 22:51:03  阅读:260  来源: 互联网

标签:c-3 32-bit linux gcc unix


我写了一个使用一些低级I / O的基本UNIX程序.没什么特别的,如果你想看一下这就是代码:

#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define BUFFSIZE 1024

int main(int argc, char *argv[])
{
    // Character buffer
    char buffer[BUFFSIZE];
    // File 1 descriptor
    int file1Desc = 0;
    // File 2 descriptor
    int file2Desc = 0;
    // Output file descriptor
    int outfileDesc = 0;
    // Count # of chars read in
    int n = 0;
    // Boolean: no stdin reads?
    unsigned char zeroSTDIN = 1;

    // Need at least two arguments, no more than 3
    if((argc < 3) || (argc > 4)){
        printf("ERROR!!!\nUsage: kitty file1 file2 <outfile>\n");
        return EXIT_FAILURE;
    }

    /** TRY TO OPEN FILES 1 AND 2 FOR READING **/
    // Check for stdin read flag
    if(argv[1][0] == '-' && argv[1][1] == '\0'){
        file1Desc = STDIN_FILENO;
        zeroSTDIN = 0;
    }
    // Otherwise just open file 1 for reading
    else{
        if((file1Desc = open(argv[1],O_RDONLY)) < 0){
            perror(argv[1]);
            printf("ERROR!!!\nUnable to open %s for reading\n",argv[1]);
            return EXIT_FAILURE;
        }
    }
    // Check for stdin read flag
    if(argv[2][0] == '-' && argv[2][1] == '\0'){
        // Only one read from stdin
        if(!zeroSTDIN){
            perror(argv[2]);
            printf("ERROR!!!\nOnly one read from stdin\n",argv[1]);
        }
        file2Desc = STDIN_FILENO;
    }
    // Otherwise just open file2 for reading
    else{
        if((file2Desc = open(argv[2],O_RDONLY)) < 0){
            perror(argv[2]);
            printf("ERROR!!!\nUnable to open %s for reading\n",argv[2]);
            if(file1Desc != STDIN_FILENO)
                close(file1Desc);
            return EXIT_FAILURE;
        }
    }

    // If argument specified, try to open output file for writing
    if(argc == 4){
        if((outfileDesc = open(argv[3],O_WRONLY|O_CREAT|O_TRUNC)) < 0){
            perror(argv[2]);
            printf("ERROR!!!\nUnable to open %s for writing\n",argv[3]);
            // Can't forget these
            if(file1Desc != STDIN_FILENO)
                close(file1Desc);
            if(file2Desc != STDIN_FILENO);
                close(file2Desc);
            return EXIT_FAILURE;
        }
    }
    // stdout otherwise
    else{
        outfileDesc = STDOUT_FILENO;
    }

    // While there is anything left to read from file 1
    while((n = read(file1Desc, buffer, BUFFSIZE)) > 0){
        // Write n chars to output file
        if(write(outfileDesc, buffer, n) != n){
            printf("Error writing to output file from file 1\n");
            return EXIT_FAILURE;
        }
    }
    // While there is anything left to read from file 2
    while((n = read(file2Desc, buffer, BUFFSIZE)) > 0){
        // Write n chars to output file
        if(write(outfileDesc, buffer, n) != n){
            printf("Error writing to output file from file 1\n");
            return EXIT_FAILURE;
        }
    }

    // Exit program
    if(file1Desc != STDIN_FILENO)
        close(file1Desc);
    if(file2Desc != STDIN_FILENO);
        close(file2Desc);
    if(argc == 4)
        close(outfileDesc);
    return 0;
}

它编译时没有任何特殊选项.但是,我想在32位模式下编译.我正在运行Fedora 15 64位,它默认为64位编译.

我正在尝试使用以下选项:

gcc -S -m32 -O3 -o llio.asm llio.c

所以我想看看正在生成的汇编代码,但是我得到以下编译错误:

In file included from /usr/include/features.h:387:0,
                 from /usr/include/fcntl.h:27,
                 from kitty.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
compilation terminated.

这个网站似乎知道我的问题:http://www.cyberciti.biz/faq/x86_64-linux-error-gnustub-32h-missing-error-and-solution/

但是,我看,这些文件似乎已经安装好了.我错过了什么?

解决方法:

我和你曾经在同一条船上,这是我在我的一个笔记文件中记下的:

yum install glibc-devel.i686

注意:i 6 86而不是i 3 86

就像你一样:gcc -m32 ……

标签:c-3,32-bit,linux,gcc,unix
来源: https://codeday.me/bug/20190902/1793803.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有