【发布时间】:2015-06-23 09:02:00
【问题描述】:
我正在努力创建一个有效的 make 文件。
我的结构
- 根/Makefile
- root/src/main.cpp
- 根/包含/
我的代码
# Define compiler
CC = g++
# Compiler flags
CFLAGS = -g -Wall
# Build target executable
DIR = /src
INCLUDES = ../include
TARGET = main
all: $(TARGET)
$(TARGET): $(TARGET).cpp
cd $(DIR) &
$(CC) $(CFLAGS) -I $(INCLUDES) -o $(TARGET) $(TARGET).cpp
clean:
cd $(DIR) &
$(RM) $(TARGET)
我的错误
make: *** 没有规则来制作目标 main.cpp', needed bymain'。停下来。
编辑
在我的 main.cpp 中,我在顶部有这一行,这意味着我的 Makefile 可以找到:#include "pugixml.hpp"
【问题讨论】:
-
考虑到你的文件,目标应该是
$(TARGET): src/$(TARGET).cpp -
嗯。好的。让我试试
-
@mpromonet 这似乎更接近,但我明白了:
cd /src & g++ -g -Wall -I ../include -o main main.cpp /bin/sh: line 0: cd: /src: No such file or directory clang: error: no such file or directory: 'main.cpp' clang: error: no input files make: *** [main] Error 1 -
DIR = /src=> 这是您尝试cd的绝对路径 -
@peter 我得到同样的错误,即使我这样做
DIR = src