Clang 找到库,Mingw32 找不到要导入的库

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

我有一些 C++ 代码可以将一些多边形渲染到窗口。它使用 SDL2 和 SDL2 gfx 库。当我在文件夹中运行 make 时,它起作用了。当我将编译器从 clang 切换到 mingw32 时它不起作用

我运行的 Ubuntu 环境设置:

sudo apt-get install libsdl2-gfx-dev
sudo apt-get install libghc-sdl-gfx-dev

我有以下文件:

制作文件

# A simple Makefile for compiling small SDL projects



# set the compiler

CC := clang



# set the compiler flags

CFLAGS := `sdl2-config --libs --cflags` -ggdb3 -O0 -Wall -lm -lSDL2 -lSDL2_gfx -Wno-c++11-narrowing



# add header files here

HDRS := header.h



# add source files here

SRCS := main.cpp



# generate names of object files

OBJS := $(SRCS:.cpp=.o)



# name of executable

EXEC := a.out #name your executable file



# default recipe

all: $(EXEC)



# recipe for building the final executable

$(EXEC): $(OBJS) $(HDRS) Makefile

    $(CC) -o $@ $(OBJS) $(CFLAGS)



# recipe for building object files

$(OBJS): $(@:.o=.cpp) $(HDRS) Makefile

    $(CC) -o $@ $(@:.o=.cpp) -c $(CFLAGS)



# recipe to clean the workspace

clean:

    rm -f $(EXEC) $(OBJS)



.PHONY: all clean

和 main.cpp

#include "SDL2/SDL.h"

#include "SDL2/SDL2_gfxPrimitives.h"

int main(int argc, char *argv[]) {

    SDL_Window *window;

    SDL_Renderer *renderer;

    SDL_Event event;



    if (SDL_Init(SDL_INIT_VIDEO) < 0) {

        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());

        return 3;

    }



    if (SDL_CreateWindowAndRenderer(320, 240, SDL_WINDOW_RESIZABLE, &window, &renderer)) {

        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s", SDL_GetError());

        return 3;

    }



    while (1) {

        SDL_PollEvent(&event);

        if (event.type == SDL_QUIT) {

            break;

        }



        SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);

        SDL_RenderClear(renderer);



        // Draw a hexagon in the center of the window

        Sint16 vx[6], vy[6];

        int x = 160, y = 120, r = 50;

        for (int i = 0; i < 6; i++) {

            vx[i] = x + r * cos(i * M_PI / 3);

            vy[i] = y + r * sin(i * M_PI / 3);

        }

        polygonRGBA(renderer, vx, vy, 6, 0xff, 0x00, 0x00, 0xff);

        // Draw the second hexagon

        Sint16 vx2[6], vy2[6];

        int rOffset = 5;

        double x2 = 160 + (r + rOffset) * 1.5, y2 = 120 + sqrt(3) / 2 * (r + rOffset);

        for (int i = 0; i < 6; i++) {

            vx2[i] = x2 + r * cos(i * M_PI / 3);

            vy2[i] = y2 + r * sin(i * M_PI / 3);

        }

        polygonRGBA(renderer, vx2, vy2, 6, 0xff, 0x00, 0x00, 0xff);



        SDL_RenderPresent(renderer);

    }



    SDL_DestroyRenderer(renderer);

    SDL_DestroyWindow(window);

    SDL_Quit();

    return 0;

}

我希望能够将编译器从 clang 切换到 x86_64-w64-mingw32-g++(使用 sudo apt-get install mingw-w64 安装)。

运行make时,我看到它确实运行了:

clang -o main.o main.cpp -c `sdl2-config --libs --cflags` -ggdb3 -O0 -Wall -lm -lSDL2 -lSDL2_gfx -Wno-c++11-narrowing

如果我把它换成

x86_64-w64-mingw32-g++ -o main main.cpp `sdl2-config --cflags --libs` -ggdb3 -O0 -Wall -lm -lSDL2_gfx

我本来希望能够生成一个 windows 可执行文件,但它看不到库

main.cpp:1:10: fatal error: SDL2/SDL.h: No such file or directory

    1 | #include "SDL2/SDL.h"

      |          ^~~~~~~~~~~~

compilation terminated.
c++ cross-platform dependency-management sdl-2 mingw32
© www.soinside.com 2019 - 2024. All rights reserved.