小编cat*_*eia的帖子

为什么我的makefile调用gcc虽然我设置了CC = g ++?

我有一个g++ -std=c++17 -Wall -Og -g -o main *.cc完美编译的小代码.现在我想要有一个makefile,到目前为止我得到了这个:

CC = g++
CFLAGS = -Wall -std=c++17 -Og -g
DEPS = random_tools.h
OBJ = main.o random_tools.o

%.o: %.c $(DEPS)
    $(CC) $(CFLAGS) -o $@ $<

main: $(OBJ)
    gcc $(CFLAGS) -o $@ $^
Run Code Online (Sandbox Code Playgroud)

然而,当我跑make它崩溃时,告诉我

g++    -c -o main.o main.cc
g++    -c -o random_tools.o random_tools.cc
gcc -Wall -o main main.o random_tools.o
main.o: In function `main':
main.cc:(.text+0x1d): undefined reference to `std::cout'
main.cc:(.text+0x22): undefined reference to `std::ostream::operator<<(int)'
main.cc:(.text+0x27): undefined reference to `std::basic_ostream<char, std::char_traits<char> …
Run Code Online (Sandbox Code Playgroud)

c c++ gcc makefile g++

-2
推荐指数
1
解决办法
903
查看次数

标签 统计

c ×1

c++ ×1

g++ ×1

gcc ×1

makefile ×1