JoeyDeVries / LearnOpenGL

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com
https://learnopengl.com
Other
11.06k stars 2.8k forks source link

How to build project with visual studio code and msys minGW-w64 gcc 12.2.0 #350

Open truongan012 opened 1 year ago

truongan012 commented 1 year ago

Hello,

I try to set up project on visual studio code using cmake and minGW-W64 (ucrt) as compiler. However, I can not compile project. It always shows error "undefined reference to sscanf" as below. Can you please help me. Thanks! I don't want to use msvc for compiling.

[main] Building folder: LearnOpenGL 1.getting_started1.1.hello_window [build] Starting build [proc] Executing command: chcp [proc] Executing command: C:\msys64\ucrt64\bin\cmake.EXE --build c:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/build --config Debug --target 1.getting_started1.1.hello_window -- [build] [1/2 50% :: 0.884] Building CXX object CMakeFiles/1.getting_started1.1.hello_window.dir/src/1.getting_started/1.1.hello_window/hello_window.cpp.obj [build] [2/2 100% :: 1.028] Linking CXX executable C:\Users\ltan\Workspaces\OpenGL\LearnOpenGL\bin\1.getting_started\1.getting_started1.1.hello_window.exe [build] FAILED: C:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/bin/1.getting_started/1.getting_started1.1.hello_window.exe [build] cmd.exe /C "cd . && C:\msys64\ucrt64\bin\g++.exe -g CMakeFiles/1.getting_started1.1.hello_window.dir/src/1.getting_started/1.1.hello_window/hello_window.cpp.obj -o C:\Users\ltan\Workspaces\OpenGL\LearnOpenGL\bin\1.getting_started\1.getting_started1.1.hello_window.exe -Wl,--out-implib,lib1.getting_started1.1.hello_window.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -LC:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/lib -lglfw3 -lopengl32 -lassimp -lfreetype -lirrKlang libSTB_IMAGE.a libGLAD.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

[build] Warning: corrupt .drectve at end of def file

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libGLAD.a(glad.c.obj): in function find_coreGL': [build] C:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/src/glad.c:2463: **undefined reference tosscanf'**

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.text$mn+0x8f4): undefined reference to `__security_cookie'

..........

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/lib/glfw3.lib(glfw.dir/Debug/wgl_context.obj):(.xdata+0x44): undefined reference to `__GSHandlerCheck' [build] collect2.exe: error: ld returned 1 exit status [build] ninja: build stopped: subcommand failed. [proc] The command: C:\msys64\ucrt64\bin\cmake.EXE --build c:/Users/ltan/Workspaces/OpenGL/LearnOpenGL/build --config Debug --target 1.getting_started__1.1.hello_window -- exited with code: 1 [build] Build finished with exit code 1

sshuy commented 1 year ago

Looks like it's failing to link the sscanf function. You might be using an outdated toolchain. Double check that your minGW-W64 (ucrt) toolchain is up to date.