提问人:Antonin 提问时间:10/24/2022 最后编辑:Antonin 更新时间:1/1/2023 访问量:340
使用 macOS 链接SDL_image
Linking SDL_image using macOS
问:
因此,我正在尝试使用 SDL2 和 Codelite 创建一个简单的 2D 游戏引擎。我已经编写了这段代码并使用 gcc 编译了它,使用它不起作用。我有一个文件夹,其中包含 和 的所有库,以及一个包含 SDL 所有头文件的文件夹。我还尝试在 Codelite 中编译它,所以我重新创建了相同的文件结构并链接了 SDL。它运行良好,直到我尝试使用 .在 和 选项卡中,我放置了与上一个项目中使用的包含文件和 lib 文件相同的路径,但它无法编译。我收到此错误:g++ src/*.cpp -o game -I include -L lib -lSDL2 -lSDL2_image
lib
SDL2
SDL_image
include
SDL_image
Project settings -> Linker
Project settings -> Compiler
Undefined symbols for architecture arm64:
"_TIFFClientOpen", referenced from:
_IMG_LoadTIF_RW in libSDL2_image.a(IMG_tif.o)
"_TIFFClose", referenced from:
_IMG_LoadTIF_RW in libSDL2_image.a(IMG_tif.o)
"_TIFFGetField", referenced from:
_IMG_LoadTIF_RW in libSDL2_image.a(IMG_tif.o)
"_TIFFReadRGBAImageOriented", referenced from:
_IMG_LoadTIF_RW in libSDL2_image.a(IMG_tif.o)
"_WebPDecodeRGBAInto", referenced from:
_IMG_LoadWEBP_RW in libSDL2_image.a(IMG_webp.o)
"_WebPDecodeRGBInto", referenced from:
_IMG_LoadWEBP_RW in libSDL2_image.a(IMG_webp.o)
"_WebPGetFeaturesInternal", referenced from:
_IMG_LoadWEBP_RW in libSDL2_image.a(IMG_webp.o)
"_jpeg_CreateCompress", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_CreateDecompress", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_calc_output_dimensions", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_destroy_compress", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_destroy_decompress", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_finish_compress", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_finish_decompress", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_read_header", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_read_scanlines", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_resync_to_restart", referenced from:
_IMG_InitJPG in libSDL2_image.a(IMG_jpg.o)
"_jpeg_set_defaults", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_set_quality", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_start_compress", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_start_decompress", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_std_error", referenced from:
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_jpg.o)
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_jpeg_write_scanlines", referenced from:
_IMG_SaveJPG_RW in libSDL2_image.a(IMG_jpg.o)
"_png_create_info_struct", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_create_read_struct", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_create_write_struct", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_destroy_read_struct", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_destroy_write_struct", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_get_IHDR", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_get_PLTE", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_get_channels", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_get_io_ptr", referenced from:
_png_read_data in libSDL2_image.a(IMG_png.o)
_png_write_data in libSDL2_image.a(IMG_png.o)
"_png_get_tRNS", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_get_valid", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_read_image", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_read_info", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_read_update_info", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_IHDR", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_set_PLTE", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_set_expand", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_gray_to_rgb", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_interlace_handling", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_longjmp_fn", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_set_packing", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_read_fn", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_rows", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_set_strip_16", referenced from:
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
"_png_set_tRNS", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_set_write_fn", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
"_png_write_png", referenced from:
_IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我真的不知道问题出在哪里,因为 SDL 链接正确。我使用配备 M1 处理器、macOS Monterey 12.6 和 Codelite 16.6.9 的 MacBook Air,我相信这是最新版本。我使用官方文档下载了它。
答:
我终于找到了在 macOS 上链接 SDL 的方法。首先,您需要在此处下载 DMG 安装程序。然后,您必须复制粘贴刚刚下载的安装程序中的文件夹(名称必须以 结尾,例如 )。因此,框架(或任何与 SDL 相关的框架,例如 )的路径将是: .然后,为了编译您的代码,您必须运行以下命令:.framework
SDL2.framework
/Library/Frameworks/
SDL
SDL2_image
/Library/Frameworks/SDL2.framework
g++ main.cpp -F/Library/Frameworks -framework SDL2 -F/Library/Frameworks -framework SDL_image -I include -o mygame
此命令假定所有 SDL 头文件 () 都位于项目的根文件夹中名为 的文件夹中。如果不是这种情况,您可以在 中找到它们。SDL.h
include
/Library/Frameworks/SDL2.framework/Headers/SDL2
评论
-framework SDL2_image
评论