c++ - 通过 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
文件在目录中都有唯一的名称。
谢谢。
解决方案
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 $@ $<
推荐阅读
- c# - 用于大量项目的 C# 字典
- javascript - Reactjs传递大写动态变量
- php - Symfony 在服务中抛出自定义 404 页面
- sql - 如何在 NVARCHAR 列 SQL Server 中插入以 0 开头的值
- google-plus - 将 google 添加到 IAM 的身份提供商 OpenID Connect
- visual-paradigm - 问题安装视觉范式classcastexception
- c++ - 在 C++ 中返回新的构造函数(*this)工厂
- node.js - 如何根据一天中的时间显示消息?
- .net - 在 vb.net 中过滤来自网络浏览器的坏词
- go - 如何在 GO 中处理全局状态