• Linux系统下编译连接C源代码


    gcc test.c -o test        一步到位的编译指令  得到 test 文件
    gcc test.c          得到 test.out 文件
    
    gcc -g -c test.c -o test    只生成目标文件(.obj文件),没有生成可执行文件(也就是说test是.obj文件)
    gcc -g test.c -o test        生成可执行文件(可以通过./test运行程序)
    

     

    -g:生成调试信息。GNU 调试器可利用该信息。
    -c:只编译并生成目标文件。(没有中间文件生成和可执行文件,如列表文件、可执行文件)
    -o:设置生成的可执行程序的名字为test
    上面的命令会产生可执行程序:test
    在Terminal中输入:./test 就可以运行该程序了。
    
    gcc main.c
    gcc main.c -o main.out
    gcc -c main.c -o main.o
    gcc max.o min.o hello.c 
    gcc max.o min.o hello.c -o hello.out
    
    
    gcc main.c -o main.out && ./main.out    只有当第一个命令执行成功的情况下,下一个命令才会执行
    echo $?          查看返回结果
    

     main函数中的参数:

    int main(int argv, char **argc[])
    {
        printf("argv is %d
    ",argv);
        int i;
        for(i=0;i<argv;i++){
             printf("argc[%d] is %s
    ", i, argc[i]);
        }
        return 0;
    }
    
    
    int main(int argc, char **argv[])
    {
        int port = 0;
        printf("program begin
    ");
        if (argc != 3) {
            printf
                ("程序参数个数不对!正确输入方法如下:
    %s ip-address port
    ",
                 argv[0]);
            exit(0);
        }
        if (atoi(argv[2]) < 0 || atoi(argv[2]) > 65535) {
            printf
                ("端口输入不对!应该是0-65535的值。程序取默认值3456
    ");
            port = 3456;
        } else
            port = atoi(argv[2]);
        printf("命令如下:%s %s %d
    ", argv[0], argv[1], port);
        return 0;
    }    
    
  • 相关阅读:
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    CF #505 B Weakened Common Divisor(数论)题解
    HDU 6425 Rikka with Badminton(组合问题签到)题解
    ZOJ 2747 Paint the Wall(离散化+暴力)题解
  • 原文地址:https://www.cnblogs.com/zhuiluoyu/p/4671377.html
Copyright © 2020-2023  润新知