lvgl / lv_port_pc_eclipse

PC simulator project for LVGL embedded GUI Library. Recommended on Linux and Mac.
https://docs.lvgl.io/v7/en/html/get-started/pc-simulator.html
MIT License
281 stars 215 forks source link

Linking Error on Windows using Clion #156

Open VanSharkholme opened 1 week ago

VanSharkholme commented 1 week ago

Hi, I'm trying to use the simulator on Windows with Clion, however when there's an error of undefined reference to 'SDL_main' during linking. The steps I took are as follows: I cloned this project, then downloaded MinGW 14.2.0 and SDL2-2.30.9, then copied everything in the SDL2 x86_64-w64-mingw32 folder to the root folder of the MinGW, finally I configured the toolset in the Clion and tried to compile this project. The compilation completed with no errors but during linking I got the error mentioned above. Heres the output:

F:/MinGW/mingw64_lvgl/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: F:/MinGW/mingw64_lvgl/lib/libSDL2main.a(SDL_windows_main.o): in function main_getcmdline': /Users/valve/release/SDL2/SDL2-2.28.4-source/foo-x64/../src/main/windows/SDL_windows_main.c:80:(.text+0x152): undefined reference toSDL_main' collect2.exe: error: ld returned 1 exit status mingw32-make[3]: [CMakeFiles\main.dir\build.make:123: F:/test/lvgl_sim/lv_port_pc_eclipse/bin/main.exe] Error 1 mingw32-make[2]: [CMakeFiles\Makefile2:109: CMakeFiles/main.dir/all] Error 2 mingw32-make[1]: [CMakeFiles\Makefile2:142: CMakeFiles/run.dir/rule] Error 2 mingw32-make: [Makefile:181: run] Error 2

Maybe there's something wrong when I'm installing SDL2? I don't know. Thanks in advance for your help

VanSharkholme commented 6 days ago

I solved this problem by changing the main function name to SDL_main in the file main.c, and the rest is working now

VanSharkholme commented 6 days ago

It turns out the problem is not solved, after changing the function name the main function that actually gets executed is the one in __main__.c, not the one in main.c

VanSharkholme commented 6 days ago

I added "#include <SDL2/SDL.h>" in the main.c and now it works

kisvegabor commented 3 days ago

It's very interesting. SDL.h is included here.

Anyway, thank you for sharing the solution.