![](/img/trans.png)
[英]How to do makefile to compile multiple .cpp files in different directories using a single makefile?
[英]How to generate dependencies with header files from different directories using a Makefile?
我正在嘗試將 ASIO 庫用於網絡項目。 我的項目和 ASIO 頭文件位於不同的目錄中。 我的 main.cpp 的編譯(除了包括asio.hpp和iostream什么都不做)工作得很好,但是make Depend命令產生一個錯誤,說asio.hpp沒有找到。 我該如何解決這個問題?
CC = g++
ASIO = -I /Users/user1/Desktop/SDK/asio-1.18.0/include
CFLAGS = -Wall -g -std=c++11 ${ASIO}
SRCS = main.cpp
#SRCS = ${wildcard *.cpp}
OBJS = ${SRCS:.cpp=.o}
INCLS = ${SRCS:.cpp= main.h}
a.out: $(OBJS)
$(CC) $(CFLAGS) $(OBJS)
$(OBJS):
$(CC) $(CFLAGS) -c $*.cpp
depend: Makefile.dep
$(CC) -MM $(SRCS) > Makefile.dep
Makefile.dep:
touch Makefile.dep
clean:
rm -f $(OBJS) a.out core a.exe
include Makefile.dep
這並不神秘:描述在哪里可以找到標題的選項在這里:
ASIO = -I /Users/user1/Desktop/SDK/asio-1.18.0/include
構建依賴項的規則在這里:
depend: Makefile.dep
$(CC) -MM $(SRCS) > Makefile.dep
注意到有什么遺漏了嗎? 該命令中不存在用於查找標題的選項。 將其更改為:
depend: Makefile.dep
$(CC) $(ASIO) -MM $(SRCS) > Makefile.dep
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.