自动生成makefile的问题, C文件成功,但CPP文件失败,请指点.谢谢.

dprk 2012-09-15 12:03:47
仿照 http://www.cnblogs.com/Safe3/archive/2009/02/10/1387460.html 做了 C 的makefile, 没有问题;

但是把文件名改为CPP后缀后,同样的仿照步骤, 在最后执行 make 时,提示 有.o文件没有指定规则,

不知应如何解决, 请高人帮忙, 谢谢!!
...全文
368 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
羽飞 2012-09-16
  • 打赏
  • 举报
回复
%.d : %.c
怎么没有看到.cpp呢
xunxun 2012-09-15
  • 打赏
  • 举报
回复
你的makefile内容呢?

Makefile内的c后缀也改了?
dprk 2012-09-15
  • 打赏
  • 举报
回复
主要的目的是希望makefile 可以自动产生文件依赖关系, 完成编译链接过程. 换了个方式, 参照这个网页做的, http://linux.chinaunix.net/techdoc/develop/2006/06/23/934841.shtml

这里有 3个C文件, 2个H文件, 一个makefile ; main.cpp fun1.cpp fun2.cpp fun1.h fun2.h
main.cpp调用了 fun1.cpp fun2.cpp fun1.h fun2.h的函数

按原文操作, 貌似makefile 没有处理 fun1, fun2 的C文件, 在末尾加了点东西,提示依赖的 .o文件都不存在.

不知道该如何解决, 继续请各位指教.

makefile内容如下 , 运行后,提示依赖的 .o 不存在;


#==============================================================================
## Customizing Section: adjust the following if necessary.
##=============================================================================
# The executable file name.
# It must be specified.
# PROGRAM := a.out # the executable name
PROGRAM := hello
# The directories in which source files reside.
# At least one path should be specified.
# SRCDIRS := . # current directory
SRCDIRS := .
# The source file types (headers excluded).
# At least one type should be specified.
# The valid suffixes are among of .c, .C, .cc, .cpp, .CPP, .c++, .cp, or .cxx.
# SRCEXTS := .c # C program
# SRCEXTS := .cpp # C++ program
# SRCEXTS := .c .cpp # C/C++ program
SRCEXTS := .cpp
# The flags used by the cpp (man cpp for more).
# CPPFLAGS := -Wall -Werror # show all warnings and take them as errors
CPPFLAGS := -Wall
# The compiling flags used only for C.
# If it is a C++ program, no need to set these flags.
# If it is a C and C++ merging program, set these flags for the C parts.
CFLAGS :=
CFLAGS +=
# The compiling flags used only for C++.
# If it is a C program, no need to set these flags.
# If it is a C and C++ merging program, set these flags for the C++ parts.
CXXFLAGS := -g
CXXFLAGS +=
# The library and the link options ( C and C++ common).
LDFLAGS :=
LDFLAGS +=
## Implict Section: change the following only when necessary.
##=============================================================================
# The C program compiler. Uncomment it to specify yours explicitly.
CC = g++
# The C++ program compiler. Uncomment it to specify yours explicitly.
#CXX = g++
# Uncomment the 2 lines to compile C programs as C++ ones.
#CC = $(CXX)
#CFLAGS = $(CXXFLAGS)
# The command used to delete file.
#RM = rm -f
## Stable Section: usually no need to be changed. But you can add more.
##=============================================================================
SHELL = /bin/sh
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
OBJS = $(foreach x,$(SRCEXTS), \
$(patsubst %$(x),%.o,$(filter %$(x),$(SOURCES))))
DEPS = $(patsubst %.o,%.d,$(OBJS))
.PHONY : all objs clean cleanall rebuild
all : $(PROGRAM)
# Rules for creating the dependency files (.d).
#---------------------------------------------------

%.d : %.c
@$(CC) -MM -MD $(CFLAGS) $
$(PROGRAM):$(IBJS)
$(CC) -o $@ $(OBJS) $(CFLAGS)
.SUFFIXES:.cpp
.cpp.o:
$(CC) $(CFLAGS) -c $<
dprk 2012-09-15
  • 打赏
  • 举报
回复
先谢谢两位了

makefile是自动生成的, 现在就是想生成个正确的makefile;

不知道如何上传附件
这自动生成的 makefile内容 , 估计看这东西,是人力所不能为的
羽飞 2012-09-15
  • 打赏
  • 举报
回复
CPP要用G++,楼主改了没

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧