我刚刚通过brew 在我的 OSX(雪豹)机器上安装了 gcc 4.8。
当我运行 make 时,它使用旧版本的 g++ 作为目标文件,使用新版本的可执行文件。
$ make
g++ -c -o myprogram.o myprogram.cc
g++-4.8 -g -Wall -o myprogram myprogram.o
我确信我的 Makefile 中的问题很简单,有人可以帮我纠正这个问题吗?
生成文件:
CC := g++-4.8
CFLAGS := -g -Wall
SRCS := myprogram.cc
OBJS := ${SRCS:.cc=.o}
TARGET := ${SRCS:.cc=}
default: all
all: $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
这是版本信息:
$ g++ --version
i686-apple-darwin10-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
$ g++-4.8 --version
g++-4.8 (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
最佳答案
您正在使用 make
的默认规则来构建目标文件。由于您的源文件是 C++(如 .cc
扩展名所示),因此除了用于链接步骤的 CC
和 CFLAGS
变量。像这样的东西应该可以做到:
CXX := $(CC)
CXXFLAGS := $(CFLAGS)
关于c++ - 使用混合版本的 gcc 的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19254868/