简体   繁体   中英

Makefile on C++ SDL2

I'm using C++ SDL2 and trying to load 3 .cpp files as well as 2 .h files.

I got this error message:

g++ main.o window.o rect.o -o output -Ldeps/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
deps/lib/SDL2main.lib(Win32/Release/SDL_windows_main.obj):(.text$mn+0x0): multiple definition of `main'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
NMAKE : fatal error U1077: 'C:\MinGW\bin\g++.EXE' : return code '0x1'
Stop.

This is what I have so far on my Makefile

CXXFLAGS = -Ideps/include -std=c++0x
LXXFLAGS = -Ldeps/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

output: main.o window.o rect.o
    g++ main.o window.o rect.o -o output $(LXXFLAGS) 

main.o: main.cpp 
    g++ main.cpp -c $(CXXFLAGS) 

window.o: window.cpp Window.h
    g++ -c window.cpp $(CXXFLAGS)

rect.o: rect.cpp rect.h
    g++ -c rect.cpp $(CXXFLAGS) 

EDIT:

#include "window.h"
#include "rect.h"

void pollEvents(Window &window, Rect &rect) {

    SDL_Event event;

    if (SDL_PollEvent(&event)) {
        rect.pollEvents(event);
        window.pollEvents(event);
    }
}

using namespace std;


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

    Window window("Cuphead", 800, 600);
    Rect rect(window, 120, 120, 100, 100, "res/char.png");

    while (!window.isClosed()) {
        pollEvents(window, rect);
        rect.draw();
        window.clear();
    }

    return 0;
}

Solved! -lmingw32 had to be removed, answers the multiple definition of `main' error as well

EDIT: using VS 2019 command prompt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM