- 此问题在此处已有答案**:
Can't build SSDL from the source code of the book C++ for the Lazy Programmers(1个答案)
3天前关闭。
我正在尝试在我的VS代码上安装SDL(https://www.libsdl.org),因为我正在阅读使用SDL的书"Will_Briggs_C ++20_for_Lazy_Programmers_Quick,_Easy,_and_Fun_C ++"。但是在书中不使用VS代码,所以我正在尝试自己管理如何安装。我遵循了Youtube教程(例如:https://youtu.be/jUZZC9UXyFs),但遇到了麻烦-我包含了库,添加了SDL2.dll文件,尝试写入Makefile命令,但编译器无法识别每个SDL命令。出了什么问题?(最后的屏幕截图)源文件来自第1章,文件夹"ch1\test-setup":https://github.com/Apress/cpp20-for-lazy-programmers
我的主文件:
#include <iostream>
#include "include\SDL2\SDL.h"
using namespace std;
int main(int argc, char **argv)
{
// Initial window setup
SSDL_SetWindowTitle("Simple tester program");
SSDL_SetWindowSize(500, 375);
// Load and play music
SSDL_Music music = SSDL_LoadMUS("media/457729__razor5__boss-battle-2-0.wav");
SSDL_VolumeMusic(int(MIX_MAX_VOLUME * 0.50));
SSDL_PlayMusic(music, SSDL_FOREVER);
// Show image
const SSDL_Image BULLSEYE = SSDL_LoadImage("media/bullseye.jpg");
SSDL_RenderImage(BULLSEYE, 0, 0);
// Set font and color
const SSDL_Font FONT = SSDL_OpenSystemFont("georgiab.ttf", 28);
SSDL_SetFont(FONT);
SSDL_SetRenderDrawColor(BLACK);
// Make a label in the middle, centered
sout << " Success! You should see\n the bullseye,\n";
sout << " read this message,\n";
sout << " and hear music.\n\n\n\n";
sout << " Hit any key to end.\n";
// End program
SSDL_WaitKey();
return 0;
}
和Makefile:
# A makefile that should work for any SSDL projects
# Adapt as needed
# -- from the SDL (Simple SDL) library, but no copyright is claimed
EXECUTABLE = a.out #Yes, you can call it this and it should run, even in MinGW
C_SOURCES = $(wildcard *.c) #We'll try to compile all .c, .cpp, and .cc files
CPP_SOURCES = $(wildcard *.cpp)
CC_SOURCES = $(wildcard *.cc)
C_OBJECTS = ${C_SOURCES: .c =.o}#Now we know what .o files we'll need to create
CPP_OBJECTS = ${CPP_SOURCES: .cpp=.o}
CC_OBJECTS = ${CC_SOURCES: .cc =.o}
ALL_OBJECTS = $(notdir $(C_OBJECTS) $(CPP_OBJECTS) $(CC_OBJECTS))
# Tell g++ where to find include files for SDL2, SSDL
INCLUDES = ../../external/SDL2-MinGW/SDL2/i686-w64-mingw32/include/SDL2 \
../../external/SDL2-MinGW/SDL2_image/i686-w64-mingw32/include/SDL2 \
../../external/SDL2-MinGW/SDL2_mixer/i686-w64-mingw32/include/SDL2 \
../../external/SDL2-MinGW/SDL2_ttf/i686-w64-mingw32/include/SDL2 \
../../external/SSDL/include \
../../external/fmt-master/include
INCLUDE_FLAGS = $(foreach dir, $(INCLUDES), -I$(dir))
LANGUAGE_FLAGS = -std=gnu++2a #Specify language standard: C++20
# MinGW can't do the fmt library
# unless we specify gnu++ to add gnu
# extensions, so I'll just use it throughout.
# Tell g++ where to find library files for SDL2, SSDL
# Sometimes library order matters. If this is a problem
# in the future -- if it says it can't find something that's in one of the
# listed libraries -- try putting libraries in different order
LIBRARIES := mingw32 ssdl SDL2main SDL2 SDL2_image SDL2_TTF SDL2_Mixer
LIBRARY_DIRS := ../../external/SDL2-MinGW/SDL2/i686-w64-mingw32/lib \
../../external/SDL2-MinGW/SDL2_image/i686-w64-mingw32/lib \
../../external/SDL2-MinGW/SDL2_mixer/i686-w64-mingw32/lib \
../../external/SDL2-MinGW/SDL2_ttf/i686-w64-mingw32/lib \
../../external/SSDL/mingw
LIB_FLAGS := $(foreach library,$(LIBRARIES), -l$(library))
LIB_DIR_FLAGS := $(foreach libdir, $(LIBRARY_DIRS), -L$(libdir))
ALL_FLAGS := $(INCLUDE_FLAGS) $(LANGUAGE_FLAGS) $(LIB_FLAGS) $(LIB_DIR_FLAGS)
##########################################################################
all: $(EXECUTABLE)
g++ -I src/include -L src/lib -o main main.cpp -lmingw32 -lSDL2main -lSDL2
#changes from Youtube
$(EXECUTABLE): $(ALL_OBJECTS)
# echo 'ALL_FLAGS :' $(ALL_FLAGS)
g++ -o $@ $^ -g $(ALL_FLAGS)
# -g means: support debugging
# $^ means: use all the objects
# -o $@ means: let the output be called $(EXECUTABLE)
clean:
rm -f $(EXECUTABLE)
rm -f *.o
rm -f core
rm -f *.ncb *.sdf
rm -r -f Debug Release .vs Backup
尝试在StackOver和SDL问题(https://github.com/libsdl-org/SDL/issues)中查找信息,但没有类似的问题。可能这是一个简单的修复,但我不明白。
1条答案
按热度按时间s3fp2yjn1#
引自书中的“入门”一章:
本书前半部分的大多数程序都使用SDL和SSDL库。
以
SSDL_
开头的标识符来自另一个名为SSDL的库(它似乎是SDL的 Package 器),您还需要安装它才能编译这些示例。根据注解(我没有这本书,只是看了Springer中的预览),在 * 附录 * A中有如何设置环境和安装两个库的说明。库源代码似乎在repo本身中,在
external/SSDL
目录here中。