簡體   English   中英

此makefile僅創建.o文件

[英]This makefile only creates .o files

我正在嘗試為一個非常簡單的程序練習使用Makefiles。 程序文件為:

main.cpp
other.cpp
other.h

我希望最終的可執行文件是Prog。

運行此命令時會發生什么情況,我得到了main.o和other.o,但沒有Prog。

我在這里想念什么?

## file Makefile

CXXOBJECTS= %.o
CXX= g++ 
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2


Prog : main.o other.o


main.o : main.cpp 
other.o : other.cpp other.h




## eof Makefile

你快到了。 您具有以下內容:

Prog: main.o other.o ## these are your dependencies
    g++ main.o other.o -o Prog

這應該給您一個名為Prog的可執行文件。 雖然實際上,一個更好的makefile是這樣的:

CXXOBJECTS= %.o
CXX= g++ 
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2

Prog: main.o other.o ## these are your dependencies
    CXX main.o other.o -o Prog

main.o : main.cpp
    CXX CXXFLAGS -c main.cpp

other.o : other.cpp
    CXX CXXFLAGS -c other.cpp

實際上,您可以使其變得更好,但我不記得我的頭上有makefile的語法糖(IDE的:P)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM