zoukankan      html  css  js  c++  java
  • 【linux】学习7

    鸟哥 22章内容

    单个源代码编译运行

    设有一个hello.c 可以用下面方式运行 生成可执行文件a.out

    [localhost scripts]$ gcc hello.c 
    [localhost scripts]$ ll hello.c a.out
    [localhost scripts]$ ./a.out
    Hello world

    也可以 会生成 目标文件hello.o 和可执行文件hello

    [localhost scripts]$ gcc -c hello.c
    [localhost scripts]$ gcc -o hello hello.o
    [localhost scripts]$ ./hello
    Hello world

    多个源代码编译运行

    设有thanks.c 和 thanks_2.c 两个源文件

    [localhost scripts]$ gcc -c thanks.c thanks_2.c     
    [localhost scripts]$ gcc -o thanks thanks.o thanks_2.o
    [localhost scripts]$ ./thanks
    Hello World
    Thank you!

    优化参数

    -O :生成优化的参数

    -Wall: 产生详细的编译信息

    [localhost scripts]$ gcc -O -c thanks.c thanks_2.c
    [localhost scripts]$ gcc -Wall -c thanks.c thanks_2.c
    thanks.c: In function 'main':
    thanks.c:5: warning: implicit declaration of function 'thanks'
    thanks.c:6: warning: control reaches end of non-void function

    加入链接的函数库

    gcc sin.c -lm -L/lib -L/usr/lib

    -l 加入函数库

    m 表示加入的是libm.so 函数库

    -L 表示函数库在其后面的路径搜索

    gcc sin.c -lm -I/usr/include

    -I 表示在后面的文件中搜索include文件

                     

    Makefile

    设有  main.c haha.c sin_value.c cos_value.c 四个源文件

    makefile中用变量来简化重复的内容,命令行命令前用<TAB>键  

    LIBS = -lm
    OBJS = main.o haha.o sin_value.o cos_value.o
    main: ${OBJS}
            gcc -o main ${OBJS} ${LIBS}
    clean:
            rm -f main ${OBJS}

    make main  表示编译执行

    make clean 表示清除已有目标文件

    make clean main 表示先清除,再执行

        

  • 相关阅读:
    三大主流负载均衡软件对比(LVS+Nginx+HAproxy)
    nginx 提示the "ssl" directive is deprecated, use the "listen ... ssl" directive instead
    centos安装nginx并配置SSL证书
    hadoop创建目录文件失败
    The server time zone value 'EDT' is unrecognized or represents more than one time zone.
    脚本启动SpringBoot(jar)
    centos做免密登录
    数据库远程连接配置
    Bash 快捷键
    TCP三次握手四次断开
  • 原文地址:https://www.cnblogs.com/dplearning/p/4128118.html
Copyright © 2011-2022 走看看