当前位置: 技术问答>linux和unix
求助makefile的问题
来源: 互联网 发布时间:2016-02-06
本文导语: 我定义了: C_SOURCES = file1.c file2.c file3.cpp file4.cpp file5.x 然后想做这样的对应: C_OBJS = $(C_SOURCES:.c=.o) 但是希望能够把.cpp也对应成.o(即,我想让C_SOURCES里面的.c和.cpp文件全都对应成.o文件) 请问该怎么写...
我定义了:
C_SOURCES = file1.c file2.c file3.cpp file4.cpp file5.x
然后想做这样的对应:
C_OBJS = $(C_SOURCES:.c=.o)
但是希望能够把.cpp也对应成.o(即,我想让C_SOURCES里面的.c和.cpp文件全都对应成.o文件)
请问该怎么写呢?
先谢谢了!
C_SOURCES = file1.c file2.c file3.cpp file4.cpp file5.x
然后想做这样的对应:
C_OBJS = $(C_SOURCES:.c=.o)
但是希望能够把.cpp也对应成.o(即,我想让C_SOURCES里面的.c和.cpp文件全都对应成.o文件)
请问该怎么写呢?
先谢谢了!
|
C_OBJS = $(C_SRC:.c=.o)
C_OBJS += $(CPP_SRC:.cpp=.o)
C_OBJS += $(CPP_SRC:.cpp=.o)
|
I am also studying the problem. I find a way in the book just now and
write it below. How wish it is useful for you!!!
.SUFFIXES: .cpp
.ccp.p:
$(CC) -xc++ $(CFALGS) -I$(INCLUDE) -c $<
write it below. How wish it is useful for you!!!
.SUFFIXES: .cpp
.ccp.p:
$(CC) -xc++ $(CFALGS) -I$(INCLUDE) -c $<
|
真老土
SOURCE_DIR = 目录
export CPPSRC := $(foreach dir,$(SOURCE_DIR),$(wildcard $(dir)/*.cpp))
SOURCE_DIR = 目录
export CPPSRC := $(foreach dir,$(SOURCE_DIR),$(wildcard $(dir)/*.cpp))
|
OBJS = $(SRCS:.c=.o)
OBJS = $(SRCS:.cpp=.o)
OBJS = $(SRCS:.cpp=.o)
|
最简单的办法是, 把扩展名不同的分别定义成几个变量
比如C_SRC: file1.c file2.c
CPP_SRC: file3.cpp file4.cpp
X_SRC: file5.x
比如C_SRC: file1.c file2.c
CPP_SRC: file3.cpp file4.cpp
X_SRC: file5.x