
makefile是什么文件(makefile文件規(guī)則)

大家好,今天小編來為大家解答makefile是什么文件這個問題,makefile文件規(guī)則很多人還不知道,現(xiàn)在讓我們一起來看看吧!linux加載驅(qū)動的兩種makefile...
大家好,今天小編來為大家解答makefile是什么文件這個問題,makefile文件規(guī)則很多人還不知道,現(xiàn)在讓我們一起來看看吧!
linux加載驅(qū)動的兩種makefile文件
二Makefile文件有兩種寫法:
一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/lib/modules/$(shelluname-r)/build
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
另外一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/usr/src/linux-headers-2.6.38-8-generic
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
比較兩者可以發(fā)現(xiàn),該兩個Makefi二Makefile文件有兩種寫法:
一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/lib/modules/$(shelluname-r)/build
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
另外一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/usr/src/linux-headers-2.6.38-8-generic
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
比較兩者可以發(fā)現(xiàn),該兩個Makefi二Makefile文件有兩種寫法:
一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/lib/modules/$(shelluname-r)/build
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
另外一種是:
#Addyourdebuggingflag(ornot)toCFLAGS
ifneq($(KERNELRELEASE),)
obj-m:=boot.o
else
KERNELDIR?=/usr/src/linux-headers-2.6.38-8-generic
PWD:=$(shellpwd)
default:
$(MAKE)-C$(KERNELDIR)M=$(PWD)modules
endif
比較兩者可以發(fā)現(xiàn),該兩個Makefile的唯一差別是KERNELDIR的不同,
le的唯一差別是KERNELDIR的不同,
le的唯一差別是KERNELDIR的不同,
makefile文件通過make編譯后用什么命令運行
makefile文件是一個命令的集合,指導shell生成需要的目標文件。生成的目標文件一般在當前目錄下。
你可以在shell下使用./@@@來執(zhí)行生成的目標文件。@@@是生成的目標文件的文件名。
我看你的問題,估計makefile不是你寫的,應該是在安裝別人的軟件。
這種情況makefile里一般有個install目標,,你在make后直接在shell中輸入makeinstall就OK了。你要是還有什么問題可以把makefile文件發(fā)給我,我給你看看。
makefile文件的含義
Makefile是一種配置文件,Makefile一個工程中的源文件不計數(shù),其按類型、功能、模塊分別放在若干個目錄中,makefile定義了一系列的規(guī)則來指定,哪些文件需要先編譯,哪些文件需要后編譯,哪些文件需要重新編譯,甚至于進行更復雜的功能操作,因為makefile就像一個Shell腳本一樣,其中也可以執(zhí)行操作系統(tǒng)的命令。
vscode怎樣在終端運行makefile文件
vscode在終端運行makefile文件需要使用version2.0版本,創(chuàng)建task,建立label,isdefault,添加makefile文件,支持選項為taget=main,cc=g++,實現(xiàn)在工程目錄下添加Makefile文件,首先安裝C/C++的兩個依賴,隨后在debug,launch會自動的生成下方的launch.json,prelauchtask,build,task.json,//主要的就是這個,表示執(zhí)行make命令(注,文件夾下需要Makefile文件),最終實現(xiàn)"group":{"kind":"build","isDefault":true}。
如何使用CMAKE生成makefile文件
CMake是一個跨平臺的安裝(編譯)工具,可以用簡單的語句來描述所有平臺的安裝(編譯過程)。他能夠輸出各種各樣的makefile或者project文件,能測試編譯器所支持的C++特性。只是CMake的組態(tài)檔取名為CmakeLists.txt。Cmake并不直接建構出最終的軟件,而是產(chǎn)生標準的建構檔(如linux的Makefile或WindowsVisualC++的projects/workspaces),然后再依一般的建構方式使用。
在linux平臺下使用CMake生成Makefile并編譯的流程如下:
編寫CmakeLists.txt。
執(zhí)行命令“cmakePATH”或者“ccmakePATH”生成Makefile(PATH是CMakeLists.txt所在的目錄)。
使用make命令進行編譯
工程實例:
一.編寫各層CMakeLists.txt
主目錄的主程序main.cpp
#include"hello.h"
externHellohello;
intmain()
{
hello.Print();
return0;
}
主目錄的CMakeLists.txt
#totherootbinarydirectoryoftheprojectas${MAIN_BINARY_DIR}.
project(MAIN)
#versionsupport
cmake_minimum_required(VERSION2.8)
#Recurseintothe"Hello"and"Demo"subdirectories.Thisdoesnotactually
#causeanothercmakeexecutabletorun.Thesameprocesswillwalkthrough
#theproject'sentiredirectorystructure.
add_subdirectory(Hello)
add_subdirectory(Demo)
#MakesurethecompilercanfindincludefilesfromourHellolibrary.
include_directories(${MAIN_SOURCE_DIR}/Hello)
#MakesurethelinkercanfindtheHelloDemolibraryonceitisbuilt.
link_directories(${HELLO_BINARY_DIR}/Hello)
link_directories(${HELLO_BINARY_DIR}/Demo)
#definethesourcecoedesofcurrentdirectoryasDIR_SRCS
AUX_SOURCE_DIRECTORY(.DIR_SRCS)
#Addexecutablecalled"MAIN"thatisbuiltfromthesourcefiles
add_executable(Main${DIR_SRCS})
#LinktheexecutabletotheHelloDemolibrary.
target_link_libraries(MainHelloDemo)
定義項目名project(MAIN),使得當前目錄可以用${MAIN_SOURCE_DIR},由于有2個子目錄,所以需要add_subdirectory它們。由于主程序會使用到其他庫,因而也需要指定連接庫所在目錄。
主目錄下的作用是利用add_executable將當前目錄下的源文件編譯成Main程序,然后通過target_link_libraries鏈接Hello和Demo庫。由于主程序文件使用了hello.h文件,所以要include_directories該目錄。
---------------------------------------------------------------------------------------------------
子目錄Demo的子程序demo.c
#include"hello.h"
Hellohello;
子目錄Demo的CMakeLists.txt
#MakesurethecompilercanfindincludefilesfromourHellolibrary.
include_directories(${MAIN_SOURCE_DIR}/Hello)
#definethesourcecoedesofcurrentdirectoryasDIR_DEMO_SRCS
AUX_SOURCE_DIRECTORY(.DIR_DEMO_SRCS)
#Addlibrarycalled"Demo"thatisbuiltfromthesourcefiles
add_library(Demo${DIR_DEMO_SRCS})
Demo目錄下的CMakeLists主要作用是利用add_library將當前目錄源碼編譯成Demo庫,由于該庫使用到hello.h文件,所以要include_directories該目錄。
---------------------------------------------------------------------------------------------------
子目錄Hello的子程序hello.h
#ifndef_hello_h
#define_hello_h
classHello
{
public:
voidPrint();
};
#endif
子目錄Hello的子程序hello.c
#include"hello.h"
#include
voidHello::Print()
{
printf("Hello,World!\n");
}
子目錄Hello的CMakeLists.txt
#definethesourcecoedesofcurrentdirectoryasDIR_HELLO_SRCS
AUX_SOURCE_DIRECTORY(.DIR_HELLO_SRCS)
#Addlibrarycalled"hello"thatisbuiltfromthesourcefiles
add_library(Hello${DIR_HELLO_SRCS})
Hello目錄下的CMakeLists主要作用是利用add_library將當前目錄源碼編譯成Hello庫。
---------------------------------------------------------------------------------------------------
二.執(zhí)行cmake命令
至此我們完成了項目中所有CMakeLists.txt文件的編寫,進入目錄step2中依次執(zhí)行命令
#cmake.
默認當前目錄,生產(chǎn)makefile
#make
最后編譯程序
makefile生成多個執(zhí)行文件要怎么寫
兩個c文件是要變成同一個可執(zhí)行程序的話那么ldflags加上-lpthread就可以了。因為ld是在將兩個.o合成可執(zhí)行文件用的。如果是分別編成兩個可執(zhí)行文件,建議寫兩個makefile使用不同的ld選項。
makefile是什么文件的介紹就聊到這里吧,感謝你花時間閱讀本站內(nèi)容,更多關于makefile文件規(guī)則、makefile是什么文件的信息別忘了在本站進行查找哦。
本文鏈接:http://www.wzyaohuidianqi.cn/ke/3051.html
