OneLoneCoder/olcPixelGameEngine

In VSC '_gfs' has not been declared. #60 does not fix it for me.

an-Iceberg opened this issue · 12 comments

/////////////////////////////////
tl;dr: Just use Visual Studio
////////////////////////////////

I'm aware that this issue has supposedly been already resolved, nevertheless my compiler is still complaining.

I am currently on a 64bit Windows machine, using the latest version of Visual Studio Code, using the latest GNU compiler.
g++ version: 9.3.0
gcc version: 9.3.0
gdb version: 9.2
cpp version: 9.3.0

After downloading the olcPixelGameEngine.h (version 2.15) and copying over the demo program provided in the header file I got the standard '<experimental/filesystem> no such file or directory'-error. I went ahead and commented that section out since it was enclosed by if clauses. After that, I went through an involuntary trip through beginner programmer hell.
I began with the 'gfs has not been declared' -error. So I went on the internet to find a solution. The only source of suggestions was this very repository. I came across #60 where the issue has apparently been resolved. I checked my own version of the header file and it says: #if defined(__linux__) || defined(__MINGW32__) So, this could not have been the source of the problem. After some additional searching, I came across a different post that suggested to download a better and more up to date version of the mingw compiler via MSYS2. Here's the video for that. So I downloaded and installed IT and specified the new compiler location in the tasks.json file.
The problem this time was that there was no debugger. So, I uninstalled MSYS2 and got myself a GNU compiler instead. After creating an environment path and specifying the new compiler/debugger location I got this working as well (I tested it on other, smaller programs I had created). Still, the 'gfs has not been declared'-error persisted. I reinstalled the compiler, I reinstalled VSCode, I restarted my computer, I tried the following compiler flags: -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -ldwmapi -lstdc++fs -static -std=c++17, I removed the ''s around MINGW32, I added some more, I changed it to MINGW64, I removed the '
's from '_gfs' but so far nothing has worked. The '_gfs has not been declared'-error still plagues me.

Regardless of your installation, the error is down to the fact that your compiler thinks it should be using the experimental version of the filesystem. If your compiler is up to date, this is resolved by specifying the C++17 standard to compile against. It could be that the order of your arguments specified to the compiler is incorrect, perhaps try specifying the standard first. I dont understand why you are debugging linux sections of the header if you are compiling on windows, but I'd suggest before continuing you start with a vanilla PGE header, as I dont know which bits youve changed. Finally since your issue contains strange formatting of the characters I think parts of it are missing. I dont know what youve been removing from what.

Hey, thanks for the quick reply. :D
Ok, so I've put all the flags into the tasks.json file before the path to the header file and it no longer shows the error. (Yay)

However, now it says 'cannot find -lpthread'. I didn't include that flag and don't know what causes the compiler to think I did. (Another one it said it cannot find is the -lstdc++fs, but I simply removed that one.)

I'd suggest running the compile command from a separate terminal to make sure which settings you really use in building your application, rather than the tasks.json of VSCode. VSCode has funny behaviors in my experience, especially for beginners, and it takes a while to set it up correctly.

I did set up my VSCode, after successfully building from the terminal first, on my Linux version.

Small update: after installing and switching to MinGW64 again there are no longer any errors with the olcPGE.h file. Instead, there are a whole host of errors with the fs_path.h file which I am currently trying to sort out. In any case, thanks a lot for the help.

I have since then switched back to the MSYS2 compiler and added the '-std=c++17' flag. I also added the environmental variable and the path to the compiler. Since there is no debugger present in MSYS2 that path is left empty. Now I'm getting linker errors with a lot of undefined references to '__imp_gl*' and 'Gdip*'.

Update: I've managed to set up everything correctly (compiler flags, etc.) but one small problem still remains: None of the compilers I have work with it. I always make sure to specify the respective compiler path in the tasks.json file.
When I use the GNU compiler it straight up says 'Command failed'.
When I use the MinGW64 compiler it shows a bunch of errors in the fs_path.h file.
When I use the MSYS2 compiler it says there are a lot of undefined references to a bunch of '__imp_gl*' and 'Gdip*' functions. (Essentially linker errors)
What should i do? Install yet another compiler?

No, that's the last thing you should do. It sounds like you need to take the time to actually learn how your toolchains work. This is important if you insist on using alternative compiler configurations.

Right now, we've no idea what compiler you are using, we've no idea of its configuration, we've no idea of your compile string, and we've no idea what errors you are seeing.

Ugh...

Where should I start/What resources do you suggest?

Well firstly, a simple question. What is your intention right now? to use PGE, or learn about toolchains. I can assure you under normal circumstances conventional compilers work just fine, but why are you using unconventional tooling for the platform you are compiling for? Why not just use Visual Studio at this stage for example?

My intention would be to deepen my experience with programming. I thought PGE would be a good place to start out for all sorts of visuals. Though I am open to learning about toolchains as well (it might be useful for the future).
As for why I use VSCode, I just searched for how to code in C++ and VSCode was the first thing google suggested. People were also praising it left and right, so I decided to use it. Since then I've completed quite a few programs in it, though nothing more than terminal applications.
So I guess the answer is because no one told me to use VS, I guess. 😅
Ok, I'll be trying it out, does VS come with a compiler for C++ or do I have to specify the path to it like in VSC?

If you go with full Visual Studio Community Edition, it comes with everything you need and is self contained and already setup, during install, select tooling to develop applications on Windows.

I think part of the problem you have experienced is that compilers are not alike, and they also don't play nicely with each others stuff and commands.

Visual Studio Code is a great tool, but by default it is not a C++ development environment. It's a text editor.

Finally, it's working. Well, time to get used to a new development environment. Thanks a lot for the help, I learnt a lot of new stuff from this.

Best way to learn. Throw yourself in the deep end, make a huge mess, then pull yourself out.

Once you've built a few bugger projects and want to move on to a command line compiler, I'd recommend cleaning your path and environmental variable. Chances are they are quite polluted from all the compilers you've installed, and may even be confusing each other.

Good luck with your project!