首页 > 解决方案 > 通过 ocaml 和 cpp 扩展的 Makefile

问题描述

我在同一个目录中有大量.ml.cpp文件,它们完全相互独立。有什么方法可以在Makefile不使用外部 bash / shell 脚本的情况下编译它们?

CC=g++
CFLAGS=-Wall -std=c++14 -Wno-unused-variable
CCML=ocamlc
SHELL := '/bin/bash'
.SUFFIXES = .cpp .ml

cpp_objs:=$(wildcard *.cpp)
ml_objs:=$(wildcard *.ml)
cpp_targets:=$(cpp_objs:.cpp= )
ml_targets:=$(ml_objs:.ml= )

targets:=$(cpp_targets) $(ml_targets)

.PHONY:all
all: $(targets) 
# all: $(cpp_targets) 
.ml: 
    $(CCML) -o $@ $<
.cpp:
    $(CC) $(CFLAGS) -o $@ $< 

Makefile仅识别我的.cpp文件有什么问题:

make: *** No rule to make target `[ML-FILES]', needed by `all'.  Stop.

更新:所有*.ml*.cpp文件在目录中都有唯一的名称。

谢谢。

标签: c++makefile

解决方案


According to the manual you are supposed to configure .SUFFIXES like a target, not like a variable:

.SUFFIXES: .cpp .ml

However, the better approach is to use pattern rules so you can drop the use of .SUFFIXES entirely.

%: %.ml
    $(CCML) -o $@ $<

推荐阅读