有没有办法 运行 使用 SDL2 和 SDL2 图像的 C++ 可执行文件,而存储库中没有 dll 文件?
Is there a way to run a C++ executable that uses SDL2 and SDL2 image without having the dll files in the repository?
我使用 LazyFoo 网站上的 Makefile 在 VS Code 中编译代码,对其进行了一些更改(当然没有触及标志),如下所示:
#OBJS specifies which files to compile as part of the project
OBJS = *.cpp
#CC specifies which compiler we're using
CC = g++
#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -IC:\mingw_dev_lib\include\SDL2
#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LC:\mingw_dev_lib\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 -lSDL2_image
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = output
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
代码似乎已编译(我编译时没有编译错误,如 "No such file or directory" 错误)但是当我 运行 我的可执行文件时,我得到这个
Error code when running exe file
现在我可以将 dll 文件添加到此 C++ 代码所在的目录中,但这会使它变得混乱。我想这样做,以便 exe 文件或其他文件知道 dll 文件在我的 PC 上的位置,这很方便,不在我的工作区目录中。
好吧,我认为人们(包括我)一开始并没有理解这个问题。我主要担心的是我无法 运行 我的代码在编译后生成的 .exe 文件。我已经链接到存储所有 headers 以及 .lib 和 .dll 文件的相关目录。如果我的工作目录中没有 .dll 文件,我无法 运行 .exe 文件(例如,如果我的 .cpp 和 .hpp 文件位于文件夹 A 中,然后我的 .dll 文件需要在 A 到 运行 .exe 文件)。
解决方法是我将 .dll 文件添加到 Windows 文件夹中。我在 Internet 的某个地方(不记得在哪里)读到 Windows 在 Windows 文件夹中寻找 运行 可执行文件的此类文件,我猜他们是对的。
我使用 LazyFoo 网站上的 Makefile 在 VS Code 中编译代码,对其进行了一些更改(当然没有触及标志),如下所示:
#OBJS specifies which files to compile as part of the project
OBJS = *.cpp
#CC specifies which compiler we're using
CC = g++
#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -IC:\mingw_dev_lib\include\SDL2
#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LC:\mingw_dev_lib\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 -lSDL2_image
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = output
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
代码似乎已编译(我编译时没有编译错误,如 "No such file or directory" 错误)但是当我 运行 我的可执行文件时,我得到这个
Error code when running exe file
现在我可以将 dll 文件添加到此 C++ 代码所在的目录中,但这会使它变得混乱。我想这样做,以便 exe 文件或其他文件知道 dll 文件在我的 PC 上的位置,这很方便,不在我的工作区目录中。
好吧,我认为人们(包括我)一开始并没有理解这个问题。我主要担心的是我无法 运行 我的代码在编译后生成的 .exe 文件。我已经链接到存储所有 headers 以及 .lib 和 .dll 文件的相关目录。如果我的工作目录中没有 .dll 文件,我无法 运行 .exe 文件(例如,如果我的 .cpp 和 .hpp 文件位于文件夹 A 中,然后我的 .dll 文件需要在 A 到 运行 .exe 文件)。
解决方法是我将 .dll 文件添加到 Windows 文件夹中。我在 Internet 的某个地方(不记得在哪里)读到 Windows 在 Windows 文件夹中寻找 运行 可执行文件的此类文件,我猜他们是对的。