找不到通过Homebrew安装的.h文件,以及

问题描述 投票:0回答:1

尝试在我的机器上正确设置SDL,但我的程序在编译时找不到头文件。

尝试获取示例 SDL 程序:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
 
int main(int argc, char *argv[])
{
 
    // returns zero on success else non-zero
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        printf("error initializing SDL: %s\n", SDL_GetError());
    }
    SDL_Window* win = SDL_CreateWindow("GAME",
                                       SDL_WINDOWPOS_CENTERED,
                                       SDL_WINDOWPOS_CENTERED,
                                       1000, 1000, 0);
    while (1)
        ;
 
    return 0;
}

...编译:

clang -I/opt/homebrew/Cellar/sdl2/2.30.3/include -L/opt/homebrew/Cellar/sdl2/2.30.3/lib -lSDL2 -o main main.cpp

...并收到此错误:

main.cpp:2:10: fatal error: 'SDL2/SDL_image.h' file not found
#include <SDL2/SDL_image.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.

到目前为止,我已经更新了我的包含路径,其中

/opt/homebrew/Cellar/sdl2/2.30.3/lib
/opt/homebrew/Cellar/sdl2/2.30.3/include
/opt/homebrew/Cellar/sdl2/2.30.3/include/SDL2

我还更新了我的 .zprofile

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib

有什么帮助吗?

c++ macos homebrew sdl
1个回答
0
投票

该标头 (

SDL2/image.h
) 是
sdl2_image
包的一部分。您还需要安装它。

您还需要链接 SDL2_image。您可以将

-lsdl2_image
添加到现有命令行,但我建议向
pkg-config
询问特定标志:

clang++ -O2 main.cpp -o main $(pkg-config --cflags --libs sdl2_image)
© www.soinside.com 2019 - 2024. All rights reserved.