簡體   English   中英

有沒有辦法在存儲庫中沒有 dll 文件的情況下運行使用 SDL2 和 SDL2 映像的 C++ 可執行文件?

[英]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)

代碼似乎已編譯(編譯時沒有編譯錯誤,例如“沒有這樣的文件或目錄”錯誤)但是當我運行我的可執行文件時,我得到了這個

運行exe文件時的錯誤代碼

現在我可以將 dll 文件添加到此 C++ 代碼所在的目錄中,但這會使它變得混亂。 我想這樣做,以便 exe 文件或其他東西知道 dll 文件在我的 PC 上的位置,這很方便不在我的工作區目錄中。

好吧,所以認為人們(包括我)起初並沒有理解這個問題。 我主要擔心的是我無法運行我的代碼在編譯后生成的 .exe 文件。 我已經鏈接到存儲所有頭文件和.lib 和.dll 文件的相關目錄。 如果我的工作目錄中沒有 .dll 文件,我無法運行.exe 文件(例如,如果 my.cpp 和 .hpp 文件位於文件夾 A 中,則 my.dll 文件需要位於 A 中才能運行。 exe文件)。

解決方法是我將 .dll 文件添加到 Windows 文件夾中。 我在 Internet 的某個地方(不記得在哪里)讀到 Windows 會在 Windows 文件夾中查找此類文件以運行可執行文件,我猜他們是對的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM