Linux c編程

c語言標準

  • ANSI C
  • POSIX(提高UNIX程序可移植性)
  • SVID(POSIX的擴展超集)
  • XPG(X/Open可移植性指南)
  • GNU C(唯一能編譯Linux內核的編譯器)

gcc 簡介

名稱:

  • GNU project C and C++ Compiler
  • GNU Compiler Collection
    管理與維護
  • GNU項目
    對C/C++編譯的控制
  1. 預處理(Preprocessing)
  2. 編譯(Compilation)
  3. 匯編(Assembly)
  4. 鏈接(Linking)

GCC文件擴展名規范

(1).c為后綴的文件,是C語言源代碼文件。

(2).h為后綴的文件,是頭文件。

(3).C,.cc、.cpp、.cp或.cxx為后綴的文件,是C++源代碼文件。

(4).h為后綴的文件,是程序所包含的頭文件。

(5).i為后綴的文件,是已經預處理過的C源代碼文件。

(6).ii為后綴的文件,是已經預處理過的C++源代碼文件。

(7).m為后綴的文件,是Objective-C源代碼文件。

(8).o為后綴的文件,是編譯后的目標文件。

(9).s為后綴的文件,是匯編語言源代碼文件。

(10).S為后綴的文件,是經過預編譯的匯編語言源代碼文件。

gcc使用

基本使用格式
$ gcc [ 選項 ] <文件名>

image.png

image.png

image.png

生成預處理文件

image.png

生成匯編文件

gcc –S hello.c –o hello.s

生成對應的目標文件

gcc -c hello.c -o hello.o

目標代碼并不能在CPU上運行,但它離二進制可執行文件已經很近了,再輸入以下編譯指令即可生成二進制可執行文件。

[root@localhost~]# gcc hello.o -o hello

image.png
文件hello.c引用的頭文件say_hello.h不在當前目錄中,也不在GCC默認的頭文件搜索路徑/usr/include中,這時我們應該使用-I選項指定搜索頭文件的特殊目錄,具體編譯指令如下:

gcc hello.c functions/say_hello.c -o hello –I functions

make

image.png

image.png
image.png

makefile文件中還可以定義一些宏,宏的作用類似于C語言中的define命令,利用它們來代表某些多處使用而又可能發生變化的內容,可以節省重復修改的工作,還可以避免遺漏

1	CC=gcc
2	CFLAGS=-Wall-c   #-Wall:編譯后顯示所有警告
3	OBJS= hello.o say_hello.o
4	hello:${OBJS}
5           ${CC} ${OBJS} -o hello
6	say_hello.o:say_hello.c say_hello.h
7           ${CC} ${CFLAGS} say_hello.c -o say_hello.o
8	hello.o:hello.c say_hello.h
9           ${CC} ${CFLAGS} hello.c -o hello.o

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390699.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390699.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390699.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

html怎么注釋掉代碼_HTML注釋:如何注釋掉您HTML代碼

html怎么注釋掉代碼HTML中的注釋 (Comments in HTML) The comment tag is an element used to leave notes, mostly related to the project or the website. This tag is frequently used to explain something in the code or leave some recommendations about the project.…

k均值算法 二分k均值算法_使用K均值對加勒比珊瑚礁進行分類

k均值算法 二分k均值算法Have you ever seen a Caribbean reef? Well if you haven’t, prepare yourself.您見過加勒比礁嗎&#xff1f; 好吧&#xff0c;如果沒有&#xff0c;請做好準備。 Today, we will be answering a question that, at face value, appears quite sim…

您好,這是我的第一篇文章

您好我是CYL 這是一個辣雞博客 歡迎指教 轉載于:https://www.cnblogs.com/pigba/p/8823472.html

08_MySQL DQL_SQL99標準中的多表查詢(內連接)

# sql99語法/*語法&#xff1a; select 查詢列表 from 表1 別名 【連接類型】 join 表2 別名 on 連接條件 【where 篩選條件】 【group by 分組】 【having 分組后篩選】 【order by 排序列表】分類內連接&#xff08;重點&#xff09;&#xff1a; inner外連接 左外&#xff0…

java中抽象類繼承抽象類_Java中的抽象類用示例解釋

java中抽象類繼承抽象類Abstract classes are classes declared with abstract. They can be subclassed or extended, but cannot be instantiated. You can think of them as a class version of interfaces, or as an interface with actual code attached to the methods.抽…

新建VUX項目

使用Vue-cli安裝Vux2 特別注意配置vux-loader。來自為知筆記(Wiz)

衡量試卷難度信度_我們可以通過數字來衡量語言難度嗎?

衡量試卷難度信度Without a doubt, the world is “growing smaller” in terms of our access to people and content from other countries and cultures. Even the COVID-19 pandemic, which has curtailed international travel, has led to increasing virtual interactio…

Linux 題目總結

守護進程的工作就是打開一個端口&#xff0c;并且等待&#xff08;Listen&#xff09;進入連接。 如果客戶端發起一個連接請求&#xff0c;守護進程就創建&#xff08;Fork&#xff09;一個子進程響應這個連接&#xff0c;而主進程繼續監聽其他的服務請求。 xinetd能夠同時監聽…

《精通Spring4.X企業應用開發實戰》讀后感第二章

一、配置Maven\tomcat https://www.cnblogs.com/Miracle-Maker/articles/6476687.html https://www.cnblogs.com/Knowledge-has-no-limit/p/7240585.html 二、創建數據庫表 DROP DATABASE IF EXISTS sampledb; CREATE DATABASE sampledb DEFAULT CHARACTER SET utf8; USE sampl…

換了電腦如何使用hexo繼續寫博客

前言 我們知道&#xff0c;使用 Githubhexo 搭建一個個人博客確實需要花不少時間的&#xff0c;我們搭好博客后使用的挺好&#xff0c;但是如果我們有一天電腦突然壞了&#xff0c;或者換了系統&#xff0c;那么我們怎么使用 hexo 再發布文章到個人博客呢&#xff1f; 如果我們…

leetcode 525. 連續數組

給定一個二進制數組 nums , 找到含有相同數量的 0 和 1 的最長連續子數組&#xff0c;并返回該子數組的長度。 示例 1: 輸入: nums [0,1] 輸出: 2 說明: [0, 1] 是具有相同數量 0 和 1 的最長連續子數組。 示例 2: 輸入: nums [0,1,0] 輸出: 2 說明: [0, 1] (或 [1, 0]) 是…

實踐作業2:黑盒測試實踐(小組作業)每日任務記錄1

會議時間&#xff1a;2017年11月24日20:00 – 20:30 會議地點&#xff1a;在線討論 主 持 人&#xff1a;王晨懿 參會人員&#xff1a;王晨懿、余晨晨、鄭錦波、楊瀟、侯歡、汪元 記 錄 人&#xff1a;楊瀟 會議議題&#xff1a;軟件測試課程作業-黑盒測試實踐的啟動計劃 會議內…

視圖可視化 后臺_如何在單視圖中可視化復雜的多層主題

視圖可視化 后臺Sometimes a dataset can tell many stories. Trying to show them all in a single visualization is great, but can be too much of a good thing. How do you avoid information overload without oversimplification?有時數據集可以講述許多故事。 試圖在…

iam身份驗證以及訪問控制_如何將受限訪問IAM用戶添加到EKS群集

iam身份驗證以及訪問控制介紹 (Introduction) Elastic Kubernetes Service (EKS) is the fully managed Kubernetes service from AWS. It is deeply integrated with many AWS services, such as AWS Identity and Access Management (IAM) (for authentication to the cluste…

一步一步構建自己的管理系統①

2019獨角獸企業重金招聘Python工程師標準>>> 系統肯定要先選一個基礎框架。 還算比較熟悉Spring. 就選Spring boot postgres mybatis. 前端用Angular. 開始搭開發環境&#xff0c;開在window上整的。 到時候再放到服務器上。 自己也去整了個小服務器&#xff0c;…

面向對象面向過程

1、面向語句&#xff1a; 直接寫原生的sql語句&#xff0c;但是這樣代碼不容易維護。改一個方法會導致整個項目都要改動&#xff0c; 2、面向過程 定義一些函數&#xff0c;用的時候就調用不用就不調用。但是這也有解決不了的問題&#xff0c;如果要維護需要改動代碼&#xff0…

python邊玩邊學_邊聽邊學數據科學

python邊玩邊學Podcasts are a fun way to learn new stuff about the topics you like. Podcast hosts have to find a way to explain complex ideas in simple terms because no one would understand them otherwise &#x1f642; In this article I present a few episod…

react css多個變量_如何使用CSS變量和React上下文創建主題引擎

react css多個變量CSS variables are really cool. You can use them for a lot of things, like applying themes in your application with ease. CSS變量真的很棒。 您可以將它們用于很多事情&#xff0c;例如輕松地在應用程序中應用主題。 In this tutorial Ill show you …

vue 自定義 移動端篩選條件

1.創建組件 components/FilterBar/FilterBar.vue <template><div class"filterbar" :style"{top: top px}"><div class"container"><div class"row"><divclass"col":class"{selected: ind…

PSP

姓名&#xff1a;袁亞琴 日期&#xff1a;11月27日 教師&#xff1a;王建民 課程&#xff1a;PSP 項目計劃日志&#xff1a; PSP Planning . Estimate Development . Analysis . Design Spec . Design Review . …