OneLoneCoder/olcPixelGameEngine

Compile with clang or (msys2) g++ in VS code does not seem to work

fabriziotappero opened this issue · 1 comments

Hello,
I am on Windows 10 and last VS code + MSYS2 env. I cloned this repo and created a main.cpp file as advised and attempted to compile it in VS code (using VS compiler):

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang++.exe" -fcolor-diagnostics -fansi-escape-codes -std=c++17 -g C:\CODE\TRYME\main.cpp -o C:\CODE\TRYME\main.exe

The first error is:

error: use of undeclared identifier 'dbuffer'; did you mean 'dfbuffer'?
vFiles.push_back(std::string(dbuffer));

changing it to:
vFiles.push_back(std::string(dfbuffer));

might fix this problem (not sure) but led to more errors

main-5c57b5.o : error LNK2019: unresolved external symbol __imp_DragAcceptFiles referenced in function "public: virtual enum olc::rcode __cdecl olc::Platform_Windows::CreateWindowPane(struct olc::v2d_generic const &,struct olc::v2d_generic &,bool)" (?CreateWindowPane@Platform_Windows@olc@@UEAA?AW4rcode@2@AEBU?$v2d_generic@H@2@AEAU42@_N@Z)
main-5c57b5.o : error LNK2019: unresolved external symbol __imp_DragQueryFileA referenced in function "public: static __int64 cdecl olc::Platform_Windows::olc_WindowEvent(struct HWND *,unsigned int,unsigned __int64,int64)" (?olc_WindowEvent@Platform_Windows@olc@@SA_JPEAUHWND@@I_K_J@Z)
main-5c57b5.o : error LNK2019: unresolved external symbol __imp_DragQueryPoint referenced in function "public: static __int64 cdecl olc::Platform_Windows::olc_WindowEvent(struct HWND *,unsigned int,unsigned __int64,int64)" (?olc_WindowEvent@Platform_Windows@olc@@SA_JPEAUHWND@@I_K_J@Z)
main-5c57b5.o : error LNK2019: unresolved external symbol __imp_DragFinish referenced in function "public: static __int64 cdecl olc::Platform_Windows::olc_WindowEvent(struct HWND *,unsigned int,unsigned __int64,int64)" (?olc_WindowEvent@Platform_Windows@olc@@SA_JPEAUHWND@@I_K_J@Z)
C:\CODE\TRYME\main.exe : fatal error LNK1120: 4 unresolved externals
clang++: error: linker command failed with exit code 1120 (use -v to see invocation)

Any idea how to fix it? I shall also add that compiling it (as advised) with msys2 g++ like this:

C:\msys64\usr\bin\g++.exe -fdiagnostics-color=always -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -ldwmapi -lstdc++fs -static -std=c++17 C:\CODE\TRYME\main.cpp -o C:\CODE\TRYME\main.exe

leads to tons of errors like this one

olcPixelGameEngine.h:4212:17: error: ‘glDeviceContext_t’ does not name a type
4212 | glDeviceContext_t glDeviceContext = 0;

Considering that VS code is one of the most popular C++ dev environments it would be very useful to explain how to compile this using VS code.

I am going to partially answer myself. I have figured out that in the fantastic world of MYS2 if you set this in your windows path:

C:\msys64\mingw64\bin

and of course you install mingw64 gcc tool, you get a lot of lib and tools. So if you then attempt to compile the pixel engine with:

g++ -o olcPixelGameEngine.exe main.cpp -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -ldwmapi -lstdc++fs -static -std=c++17

with your main.cpp starting with:

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

Everything should compile file. Also this is the tasks.json that should make VS Code compile it with CTRL+F5

{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: MINGW g++.exe build active file",
"command": "C:\msys64\mingw64\bin\g++.exe",
"args": [
"${file}",
"-fdiagnostics-color=always",
"-luser32",
"-lgdi32",
"-lopengl32",
"-lgdiplus",
"-lShlwapi",
"-ldwmapi",
"-lstdc++fs",
"-static",
"-std=c++17",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

So, al least one method works! Any idea how to fix the clang compiler error?