I can't compile with Visual Code

Hello, I have a copy of CGE cloned from github. It’s works nice with lazarus, but I tried to use Visual code, but I got the folliwng error:


Here is the configuration of the VS.

What’s wrong?
/BlueIcaro

The “Path to Free Pascal Compiler executable” should be the full filename to the FPC executable, ending like fpc.exe (on Windows). You specified there only the directory, ending with ...x86_64-win64\. Looks like you should just add fpc.exe.

The hint visible at the screenshot above tried to communicate this, but I recognize this was confusing, it said “Path to the Free Pascal Compiler executable…” (which could be interpreted as filename or directory; and in fact right below, for FPCDIR, we say “path” to mean directory…). I improved it now, to say this:

Note: You could also just get CGE from Download | Castle Game Engine , which has a bundled FPC version, and then the bundled FPC would be used automatically.

Hello, with downloaded version it’s works nice. If I use a compiled version from Github, it’s doesn’t work.

/BlueIcaro

With the downloaded version from Download | Castle Game Engine , it should indeed work out-of-the-box, and there should be no need to even configure the PP mentioned above. That’s because it contains a ready FPC installation (“bundled”) and our VS Code extension auto-detects it.

If this FPC is good enough for you, then go ahead and use it :slight_smile: It’s the latest (3.2.2) stable FPC, and it should be good for most “normal” purposes (unless you need to cross-compile e.g. for Android | Manual | Castle Game Engine ).

To be clear, with the version you compiled yourself from GitHub, and with your own installed FPC, it should also work – if your PP will be correct. If it still fails for you, then we can debug it more, please

  • Show all your “Castle Game Engine” extension settings in VS Code
  • Show us the contents of your c:/lazarus/fpc/3.2.2/bin/x86_64-win64/ .

Hello, this is the configuration of VS extension:


And here is the content of c:/lazarus/fpc/3.2.2/bin/x86_64-win64/

Thanks

/BlueIcaro

Looking at the screenshot, you didn’t fix the PP setting as I advised in my answer on I can't compile with Visual Code - #2 by michalis :slight_smile:

In PP you need to specify the full filename (not only path) to the FPC, in case of Windows – with fpc.exe at the end. I have improved the “hint” at this setting, so this is now communicated clearly there:

Full filename of the Free Pascal Compiler executable. This should include the file name at the end, like fpc.exe (Windows) or fpc (Unix without FpcUpDeluxe) or fpc.sh (Unix with FpcUpDeluxe). Leave blank to auto-detect (will detect e.g. FPC bundled with CGE).

Hi, I’m sorry, it was a old image. Here is the last one.


As you can see, it’s the same path that I have in my Lazarus instalation

Here is a image, that shows the path to fpc is working from command line.

Thanks
/blueIcaro

Hello, I found some thing, may be, interesting.
If I run from command line in bin folder: castle-engine.exe output-environment fpc-exe
I got any information. If I do this in the bin folder of the installed version I got the right path to the fpc

/BlueIcaro

Thank you! Hm, everything seems to be OK in the images you posted. The PP setting is indeed correct, this is how it should look like.

Ah, I think I guess where’s the problem – the PP setting is using this FPC for code completion, but it is not passed to the build tool as FPC location to execute. We should use it. I’ll take a look at it ~tomorrow and get back here!

As an immediate workaround, for today, you can add the directory with your FPC (so, c:/lazarus/fpc/3.2.2/bin/x86_64-win64/) to the PATH environment variable of your system. See guides like How to Add to Windows PATH Environment Variable or How to Set the Path and Environment Variables in Windows (note that you only need to edit the “User” Path value, not the “System” one). Remember to close and reopen all applications to make them account for the new variable value.

That is indeed related but also normal. That is, our “build tool” (that you run by castle-engine.exe output-environment fpc-exe) only looks for FPC bundled with CGE (which you don’t have if you downloaded CGE sources-only from GitHub), or FPC on the PATH.

The build tool (when run on command-line in a normal fashion) is not aware about the FPC location you have configured in the VS Code settings, or in the CGE editor.

So, this is normal, this is not a bug. To make it work, add the directory with your FPC to PATH, following advise above. In this case, this is not “workaround”, it’s just a valid thing to do – build tool has to be made aware of FPC location, and the way to do this is by setting PATH.

Fixed!

Our VS Code extension for Castle Game Engine now uses the FPC path you set more fully. The build tool (which is executed when you press “Compile” from VS Code) will reliably use this FPC.

There’s no need to have FPC on $PATH anymore to use CGE from VS Code. It should be enough to configure FPC location in VS Code (which you already did, as seen in your past screenshots), and then hit “Compile” in VS Code and it should “just work”.

Make sure your VS Code extension for Castle Game Engine has been updated to 1.3.0 (which should happen automatically once you run VS Code) and retest, it should all be solved now :slight_smile:

1 Like

Hi, thanks Michalis. Now it’s working.
I think use Visual code for CEG develop is a good idea, because is light. I don’t need all power of Lazarus to do it.


/blueicaro

Thank you for confirming!

And yeah, I like VS Code too. I actually switched to VS Code for most of my coding (including Castle Game Engine) after using Emacs for ~20 years (news) and I’m happy from the switch :slight_smile: And I use our VS Code extension for CGE myself all the time.