SHADERed icon indicating copy to clipboard operation
SHADERed copied to clipboard

c++ export is hard to compile in windows

Open 0x4E69676874466F78 opened this issue 3 years ago • 3 comments

First of all, thanks for such a cool editor!

I tried to build in msvc 2019 and got an error: Error LNK2019 unresolved external symbol "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ I got tired of suffering with the CMAKE config in VS and I tried to build using MSYS2 (with mingw compiler), after agonizing over there, I ended up with a similar problem undefined reference to 'WinMain' in the end, it was necessary to add #define SDL_MAIN_HANDLED (before #include <GL/glew.h>) to export.cpp and then it compiled!

You also need to install mingw-w64-x86_64-cmake and don't use the default cmake from msys2 (remove it and restart ) otherwise you won't get past the Could NOT find OpenGL error (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY) even if you install mingw64/mingw-w64-x86_64-mesa.

I was also able to build without any cmake this way: g++.exe -mwindows export.cpp -o export.exe -lmingw32 -lsdl2 -lopengl32 -lglu32 -lglew32

I also had to comment: glUniform4fv(glGetUniformLocation(Image_SP, "iMouse"), 1, glm::value_ptr(shaderVariable)); because it couldn't defined shaderVariable: error: 'shaderVariable' was not declared in this scope.

Some tips

For static build (no need lib*.dll but need put SDL2.dll and glew32.dll in exe folder): Add in CMakeLists.txt -static by replace target_link_libraries(ShaderProject GLEW::GLEW SDL2::SDL2) to target_link_libraries(ShaderProject GLEW::GLEW SDL2::SDL2 -static)

Compile without console window: Replace in CMakeLists.txt add_executable(ShaderProject ${SOURCES}) to add_executable(ShaderProject WIN32 ${SOURCES})

For beginners: cmake . && cmake --build . for configure and build by cmake You need to install glew sdl2 glm packages via pacman -S packagename (use search via pacman -Ss packagename).

0x4E69676874466F78 avatar Sep 17 '22 15:09 0x4E69676874466F78

It's pretty strange you want to compile w/o cmake when cmake output is explicitly what the export generates, then complain it's hard. :-) Thanks for documenting how to do it for the curious though!

ctrlcctrlv avatar Jan 12 '23 16:01 ctrlcctrlv

@ctrlcctrlv No, you've got it wrong. All the problems are present and with the building through cmake. I wrote without cmake as a supplement no more.

0x4E69676874466F78 avatar Jan 12 '23 21:01 0x4E69676874466F78

Oh! Sorry, I see that now.

ctrlcctrlv avatar Jan 12 '23 21:01 ctrlcctrlv