Im using gcc 8.1.0 compiler, to compile my cpp code to start using SDL2. However when running the test code
#include <iostream>
#include <SDL2/SDL.h>
int main(int argc, char *argv[])
{
std::cout << "hello workd" << std::endl;
return 0;
}
And to run it im using this cmd.
gcc -o main main.cpp -Isrc/include -Lsrc/lib -lSDL2main -lSDL2 -lstdc++ -std=c++11 -m64
And i get this error: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to 'WinMain' collect2.exe: error: ld returned 1 exit status
If i add -municode tag, it gives this: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o):crt0_w.c:(.text+0x21): undefined reference to wWinMain' collect2.exe: error: ld returned 1 exit status
Currently Following this tutorial: https://www.youtube.com/watch?v=H08t6gD1Y1E&list=LL&index=1&t=120s&ab_channel=HerbGlitch
My folder structure:
project file has [src,main.cpp,SDL2.dll]
'src' folder has 'include' and 'lib' from SDL2 mingw development library.
EDI: When I tried using -lmingw64 it gives cannot find -lmingw64 collect2.exe: error: ld returned 1 exit status
I also tried ctrl+s to properly save the file before compiling, nothing worked.
EDIT: MY SOLUTION: I was trying to do everything with 64 bit compiler and files, couldn't solve the problem as I was stuck on the error produced by -lmingw64 flag.
I Uninstalled the 64 bit compiler and replaced it with 32 bit compiler and replaced all files with 32 bit version, and it worked using -lmingw32 flag.
I guess, I didn't install the 64 bit compiler properly/didn't add something important to path, as I added all the path variables manually.