c++ - Linker can't find mingw64 library? - Stack Overflow

admin2025-05-02  7

"make" gave me this error message:

g++ -I src/include -L src/lib -o main main.cpp -lmingw64 -lSDL2main -lSDL2
/usr/bin/ld: cannot find -lmingw64: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1

I have no clue what to do as mingw64 seems to have been installed when I do

gcc --version
g++ --version
gdb --version

I can't seem to find any fixes for this error

This is my code so you can run it to see if I missed anything

Makefile

all:
    g++ -I src/include -L src/lib -o main main.cpp -lmingw64 -lSDL2main -lSDL2

main.cpp

#include <iostream>
#include <SDL2/SDL.h>

const int WIDTH = 800, HEIGHT = 600;

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

    SDL_Window *window = SDL_CreateWindow("title",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,WIDTH,HEIGHT,SDL_WINDOW_ALLOW_HIGHDPI);

    if(NULL == window){
        std::cout << "could not create window:"<< SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Event windowevent;

    while (true)
    {
        if (SDL_PollEvent(&windowevent))
        {
            if (SDL_QUIT == windowevent.type)
            {
                break;
            }
            
        }
        
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return EXIT_SUCCESS;
}
转载请注明原文地址:http://www.anycun.com/QandA/1746135055a92057.html