【问题标题】:Makefile doesn't understand g++ but terminal doesMakefile 不理解 g++ 但终端可以
【发布时间】:2018-05-19 02:42:17
【问题描述】:

生成文件

# Assignments
#########################################################
CC := g++
SRC := src
BUILD := build
INCLUDE := include
TARGET := bin/driver
LIB := lib
TESTS := tests

CFLAGS := -g -Wall -Wextra

PATH := -I $(INCLUDE)

#########################################################

driver: Logbook.o Entry.o main.o
    g++ Logbook.o Entry.o main.o -o driver

main.o: main.cpp
    g++ -c main.cpp 

Logbook.o: 
    g++ -c $(PATH) $(LIB)/Logbook.cpp

Entry.o:
    g++ -c $(PATH) $(LIB)/Entry.cpp 

test:
    g++ -c $(PATH) $(LIB)/Logbook.cpp

clean:
    rm -f *.o *.exe driver

标准输出

mint@mint-VirtualBox ~/Desktop/Logbook $ ls
googletest  include  lib  main.cpp  Makefile  README.md  src
mint@mint-VirtualBox ~/Desktop/Logbook $ make
g++ -c -I include lib/Logbook.cpp
make: g++: Command not found
Makefile:47: recipe for target 'Logbook.o' failed
make: *** [Logbook.o] Error 127
mint@mint-VirtualBox ~/Desktop/Logbook $ ls
googletest  include  lib  main.cpp  Makefile  README.md  src
mint@mint-VirtualBox ~/Desktop/Logbook $ g++ -c -I include lib/Logbook.cpp 
mint@mint-VirtualBox ~/Desktop/Logbook $ ls
googletest  include  lib  Logbook.o  main.cpp  Makefile  README.md  src
mint@mint-VirtualBox ~/Desktop/Logbook $ 

预期的结果是 g++ 在从 makefile 内部调用时可以工作,但显然不能 这里到底发生了什么?在终端中应该有标签并运行编译命令,但 Makefile 只是不想同意 g++ 命令存在。

【问题讨论】:

  • 你能增加图片的大小吗,它们很难阅读。

标签: c++ makefile directory


【解决方案1】:

不要调用变量PATH,它会覆盖告诉 Makefile 在哪里查找二进制文件的默认环境变量。只需将其重命名为CCFLAGS 左右即可。

CCFLAGS := -I $(INCLUDE)

Logbook.o: 
    g++ -c $(CCFLAGS) $(LIB)/Logbook.cpp

有关 PATH 的更多详细信息,例如这里:https://en.wikipedia.org/wiki/PATH_(variable)

【讨论】:

    猜你喜欢
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    相关资源
    最近更新 更多