修改makefile以编译.cc和.cpp文件 [英] Modifying a makefile to compile .cc and .cpp files

查看:689
本文介绍了修改makefile以编译.cc和.cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改我的Makefile以支持.cpp和.cc,但是,我不断收到错误消息,例如

I am trying to modify my makefile to support .cpp and .cc, however, I keep getting an error such as

target `source/systemFuncs.cpp' doesn't match the target pattern

我正在修改现有的支持.cc的makefile,我也想使它编译.cpp,但是我不确定如何。

I am modifying an existing makefile that support .cc and I want to make it also compile .cpp, but I am unsure how. This was originally a make file for a nacl project.

如何同时编译.cpp和.cc?

How can I compile both .cpp and .cc?

与makefile相关的内容:

Related content to the makefile:

x86_32_OBJS:=$(patsubst %.cc,%_32.o,$(CXX_SOURCES))
$(x86_32_OBJS) : %_32.o : %.cc $(THIS_MAKE)
    $(CXX) ${INCDIRS} -o $@ -c $< -m32 -O0 -g $(CXXFLAGS)

$(PROJECT)_x86_32.nexe : $(x86_32_OBJS)
    $(CXX) -o $@ $^ -m32 -O0 -g $(CXXFLAGS) $(LDFLAGS)

CXX_SOURCES中同时包含.cc文件和.cpp文件,因此它需要能够同时编译这两个

CXX_SOURCES has both .cc files AND .cpp files in them, so it needs to be able to compile both

推荐答案

您并没有给我们太多帮助,但是我会一个推测。我认为您已将 source / systemFuncs.cpp 添加到 CXX_SOURCES 。然后点击以下行:

You haven't given us much to go on, but I'll make a guess. I think you added source/systemFuncs.cpp to CXX_SOURCES. Then Make hit this line:

x86_32_OBJS:=$(patsubst %.cc,%_32.o,$(CXX_SOURCES))

将 .cc替换为 _32.o,并保留了 source / systemFuncs.cpp 保持不变。然后,make尝试将此名称输入到预期为 _32.o的规则中,并崩溃了。

which replaced ".cc" with "_32.o", and left source/systemFuncs.cpp untouched. Make then tried to feed this name into a rule that expected "_32.o", and crashed.

尝试一下:

CPP_SOURCES += source/systemFuncs.cpp

x86_32_CPP_OBJS:=$(patsubst %.cpp,%_32.o,$(CPP_SOURCES))

$(x86_32_CPP_OBJS) : %_32.o : %.cpp $(THIS_MAKE)
    $(CXX) ${INCDIRS} -o $@ -c $< -m32 -O0 -g $(CXXFLAGS)

幸运的是,这将证明是粗糙但有效的。

With luck, this will prove crude but effective. Further improvements will be possible later.

编辑:

如果两组文件名都必须在一个变量中( CXX_SOURCES ),您可以像这样将它们分开:


If both sets of filenames must be in one variable (CXX_SOURCES) you can separate them like this:

CC_SOURCES :=  $(filter %.cc, $(CXX_SOURCES))
CPP_SOURCES := $(filter %.cpp, $(CXX_SOURCES))

足够吗?

这篇关于修改makefile以编译.cc和.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆