【问题标题】:Why does Makefile return a bunch of command not founds?为什么 Makefile 会返回一堆未找到的命令?
【发布时间】:2021-08-30 22:01:03
【问题描述】:

我正在尝试学习惰性 foo 制作 sdl2 教程。一切都很好,然后突然我打开 vscode 看到 sdl.h 包含下的红色曲线,现在项目甚至无法编译。有什么想法吗?

生成文件

#OBJS specifies which files to compile as part of the project
OBJS = 01_hello_SDL.cpp

#CC specifies which compiler we're using
CC = g++

#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -IC:\libs\sdl_32\include\SDL2

#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LC:\libs\sdl_32\lib

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -w -Wl,-subsystem,windows

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = project

#This is the target that compiles our executable
all : $(OBJS)
    $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

终端输出

$ ./Makefile
./Makefile: line 2: OBJS: command not found
./Makefile: line 5: CC: command not found
./Makefile: line 8: INCLUDE_PATHS: command not found
./Makefile: line 11: LIBRARY_PATHS: command not found
./Makefile: line 16: COMPILER_FLAGS: command not found
./Makefile: line 19: LINKER_FLAGS: command not found
./Makefile: line 22: OBJ_NAME: command not found
./Makefile: line 25: OBJS: command not found
./Makefile: line 25: all: command not found
./Makefile: line 26: CC: command not found
./Makefile: line 26: OBJS: command not found
./Makefile: line 26: INCLUDE_PATHS: command not found
./Makefile: line 26: LIBRARY_PATHS: command not found
./Makefile: line 26: COMPILER_FLAGS: command not found
./Makefile: line 26: LINKER_FLAGS: command not found
./Makefile: line 26: OBJ_NAME: command not found
./Makefile: line 26: -o: command not found

【问题讨论】:

  • 您为什么要尝试将 Makefile 作为 shell 脚本执行?而是运行 make 并让它像往常一样解释它在工作目录中找到的任何 Makefile。
  • 当我运行“ming32-exe”时它可以工作,但我在#include 下仍然有红色的suggles,我认为这与此有关,但我不知道如何修复它。它工作正常,然后开始看到此错误以修复我的包含路径,但据我了解,一切都已到位,所以我不明白

标签: c++ makefile mingw sdl


【解决方案1】:

Makefile 是一个文件,当您在类似 Unix 的 shell(如 MSYS2)中运行 make 时使用该文件;如果您使用的是 Windows shell(命令提示符、Power Shell),则为mingw32-make

如果您在#include <SDL.h> 上遇到编译器错误,那么您应该检查SDL.h 是否存在于使用-I 标志指定给编译器的任何路径中。

同样,如果您收到有关 -lSDL2 找不到库的错误,您应该检查 libSDL2.a(或共享库的 libSDL2.dll.a)是否存在于使用 -L 标志指定的任何路径中链接器。

要查看make 执行的实际命令,您可以运行make V=1 以打开详细模式。 (mingw32-make 也是如此)

【讨论】:

  • sdl 的东西与 vscode 找不到目录有关,我只是禁用了错误消息,但我不明白的是,mingw32-make.exe 可以编译我的 sdl 项目并且 './Makefile 返回所有未找到的命令,但是 - 如果我在另一个没有要链接的库的项目中执行此操作,则调用 ./Makefile 确实有效,并且 mingw32-make.exe 失败。它完全相反。
  • 再一次,如果 Makefile 是程序或脚本,您不能单独运行它。改为运行make。它将查找文件Makefile。您也可以使用make -f Makefile 指定它
  • 好吧,为什么它在基本项目中可以工作,但 mingw32-make.exe 却不行?我不确定这里的结果不一致。
  • 我不明白你想说什么。 ./Makefile 永远不会工作。
猜你喜欢
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-06
  • 2011-05-24
相关资源
最近更新 更多