繁体   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