Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#pragma once errors with simple first person UE5 project #22

Open
max-cis opened this issue Aug 29, 2022 · 66 comments
Open

#pragma once errors with simple first person UE5 project #22

max-cis opened this issue Aug 29, 2022 · 66 comments

Comments

@max-cis
Copy link

max-cis commented Aug 29, 2022

Hi,
I have used your extension to remove most of the problems but I am still getting a few.
Unfortunately, I am required to use macos for this and I am not particularly familiar with various things.

My current setup is an i7 iMac so not on the M1 or anything. I was hoping
I have set up the cppproperties for intelli sense to "macos-clang-x64". I left the compiler path to the default. Also, I am only using the option from your extension "UEIntellisenseFixes.enableFixes": true, "UEIntellisenseFixes.cppStandard": "c++17"`.

Any ideas on what I could do to fix this? I have attached a picture of the errors. Maybe it helps.

Thanks,
M
Screenshot 2022-08-29 at 11 34 31

@boocs
Copy link
Owner

boocs commented Aug 29, 2022

Some things to try:

Make sure you can build successfully first with the 'Editor' suffix config like so:
image

This is a VSCode Build Task. TestFps is the project name and notice the 'Editor' suffix. Win64 might be Mac for you.

This will create some files needed for Intellisense if they're missing.

Now you'll need to reset your project which will add the new file paths to Intellisense configs.
image

Right click on your *.uproject file and choose Generate Visual Studio Project Files (or something similiar). If you can't find it you can also do this by loading your project in to the UE5 Editor and choose this option from the Tools menu. It's called 'Refresh Visual Studio Code Project'. It's also possible inside VSCode. One of the debug configs is called Generate Project Files. You do need to install the Microsoft C# extension for it to work though.

Restart VSCode and see if it works.

Another thing to try, maybe the config you're using is bugged.
image

You can click the Win32 which is the name of one of the intellisense configs. Yours will probably be named something different. When you click it you'll get a menu with two choices. Click the opposite config that's currently active.
image

@max-cis
Copy link
Author

max-cis commented Aug 30, 2022

Thanks for getting back so quickly.
I managed to figure out the reason behind the problems.

I am not sure if it is because I didn't set up the compiler in your extension properly, but I needed to add the following two parameters to the c_cpp_properties.json file to ensure that all the errors went away.

  "includePath": ["${workspaceFolder}/**"],
  "compilerPath": "/usr/bin/clang",

I am not sure if you think it is worth adding this to the extension so it includes these two parameters when it corrects the file.

I don't know how to do it, but I think could be marked as a workaround in GitHub. May help other MacOS users.

@boocs
Copy link
Owner

boocs commented Aug 30, 2022

I do have a compiler path setting in my extension but the includePath making it work is weird.

It would mean that it's not using the compile commands file for Intellisense and instead using the cpptools includePath setting.

This could also mean you're not using the 'smart' Intellisense and instead using the other intellisense called 'Tag Parser'.

Pretty strange. Are you sure you need the includePath setting for it to work?

@leonfs
Copy link

leonfs commented Aug 30, 2022

I'm running on a Mac M1 and I've been using the extension to fix a few IntelliSense problems (thanks by the way), but the whole discovery of files was really really slow. The loading of the symbols and suggestions would take ages. But, after reading the official docs of VSCode about C++ and seeing this issue thread, I decided to add the includePath property in the c_cpp_properties.json. I have to say it worked like a treat! Now the whole discovery of files and IntelliSense is super fast.

As a reference, my compiler path is: "compilerPath": "/usr/bin/clang++"

@boocs
Copy link
Owner

boocs commented Aug 30, 2022

@leonfs
I think that means you're using the Tag Parser Intellisense(which is fine). The latest UE4/UE5 use compile commands which override the includePath setting so includePath shouldn't be affecting anything.

The compile commands must have include errors which forces VSCode to fall back to instead use Tag Parser Intellisense.

@leonfs
Copy link

leonfs commented Aug 30, 2022

You might be right, actually. How do you find those include errors @boocs? For some reason, navigating with IntelliSense the UE code is super fast, but when I have to navigate my project's code, it is super slow.

There is clearly something not right.

@boocs
Copy link
Owner

boocs commented Aug 30, 2022

Tag Parser Intellisense is super fast but not as smart as the default Intellisense which is fast with cpp files but slow with header files because of how it works(updates too often whenever you type).

You should be able to look at the cpptools(C_CPP) extension logs. The setting is called Logging Level. Set it to debug.
I actually should just make a guide because it's really easy to check with the cpptools log. It'll take some time but let me do that.

@leonfs
Copy link

leonfs commented Aug 31, 2022

Also - In the logs of the C++ extension I see this:

[8/31/2022, 9:17:18 AM] For C source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/opt/homebrew/opt/llvm@12/bin/clang"
[8/31/2022, 9:17:18 AM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.
[8/31/2022, 9:17:18 AM] For C++ source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/opt/homebrew/opt/llvm@12/bin/clang"
[8/31/2022, 9:17:18 AM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.
[8/31/2022, 9:17:19 AM] For C++ source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"

@max-cis
Copy link
Author

max-cis commented Aug 31, 2022

@leonfs just to make you aware that I am running an older i7 iMac so my compiler settings will differ from yours. Make sure you are not confusing the settings. There is another thread regarding M1 settings.

@boocs I will have a look and report back. Sorry, got caught up in other things.

@boocs boocs mentioned this issue Aug 31, 2022
@boocs
Copy link
Owner

boocs commented Aug 31, 2022

@leonfs I created a new issue for you called M1 Mac issues

@max-cis
Copy link
Author

max-cis commented Aug 31, 2022

@boocs I started a brand new project and set the path in your extension. The settings are as follows:

    "UEIntellisenseFixes.compiler.path": "/usr/bin/clang",
    "UEIntellisenseFixes.compiler.strictPath": true,

There were no immediate errors, but it was stuck on Loading... for ages. I then got an error with the include path and then it found things. It did take very long in comparison to when the includepath was set before.

As far as I can tell, I am using the Default intelliSense. Is that not the proper one? The setting is set as follows:

"C_Cpp.autocomplete": "Default"

Any way to check if it is using the correct IntelliSense? Also, I haven't switched on your optimisation setting.

@boocs
Copy link
Owner

boocs commented Aug 31, 2022

I don't know if you have have my latest extension version 3.2.0. But I changed the strict setting documentation to say only use it if the extension's path setting is the full compiler path.

Make sure to change it to the full xcode/clang or clang++ path.

Makes me think I should just detect if it's a full path and error if it's not(when using the strict setting).

If you decide to remove the strict setting you should do a Generate Project File on your project.

@max-cis
Copy link
Author

max-cis commented Aug 31, 2022

I did read that in your extension. However, when you read the output it states that it is better to actually have the box ticked. When you say full path you mean absolute rather than relative, right?

@boocs
Copy link
Owner

boocs commented Aug 31, 2022

Yep, I guess my extension change wouldn't have worked if /user/bin/clang is also an absolute path on some systems. Maybe I'll just detect it on Mac and make sure if you use the strict setting that xcode is in the path somewhere.

So basically on Mac if using the strict setting your path setting should look something like this:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang or clang++ since clang++ is what ue5 default compiles with on Mac.

@boocs
Copy link
Owner

boocs commented Aug 31, 2022

You can also remove the strict setting and Generate Project Files to get back the full xcode clang path in your compile commands file.

After you Generate Project Files, you can also check my extension log to see what the compile commands compiler path is being set to by the Unreal Engine.

Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe" @"D:\EJ\Documents\Unreal Projects\CPPTest\.vscode\compileCommands_CPPTest\CPPTest.211.rsp"

For example, my project's extension log above it says it's using "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe"

@boocs
Copy link
Owner

boocs commented Aug 31, 2022

Once you figure out the full path that Unreal chooses you can just copy and paste that into the path setting and reenable the strict setting. Actually since they're going to be the same anything I guess you don't need to use the strict setting if you don't want lol.

I'm thinking that maybe the strict setting was a bad idea and just reading the compile commands compiler setting and auto pasting it into the path setting would be better. That way it's up to you to install the correct clang and up to Unreal to detect and use the correct clang.

@boocs
Copy link
Owner

boocs commented Aug 31, 2022

Here's how I'll fix this.

  • Recommend not using strict setting anymore. (Keep it for Windows users who want to compile with clang or future compiler bugs)
  • Without the strict path setting it will default pull Unreal's clang path it uses in the compile commands and copy it to the extension's path setting. Now VSCode's compilerPath and compile commands setting will be in parity.

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

I released 3.3.0 with the path fixes. You can remove the strict setting and reset your project(Generate Project Files) to fix it.

The path setting will now be auto set based on what compiler Unreal chooses.

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

I've released my guide on how to check for VSCode config bugs. This is just a partial Include Errors release. Note: This will get reorganized and changed.

https://github.com/boocs/Unreal-VSCode-diy-config-check-github

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

Ok, so I downloaded your latest version. Removed the strict flag and refreshed the project twice from Unreal 5.
Restarted VSCode, got the extension to fix things and then I got errors with the includePath. See image below:
Screenshot 2022-09-01 at 15 17 11

I checked c_cpp_properties.json and it is set up as follows:

 {
            "name": "Test3Editor Editor Mac Development (Test3)",
            "intelliSenseMode": "clang-x64",
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compileCommands": "/Users/lmnicosia/CIS/Projects/UE5/Test3/.vscode/compileCommands_Test3.json",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
 }

I tried adding "includePath": ["${workspaceFolder}/**"] to c_cpp_properties.json but that didn't fix anything.
I set the strict flag and that made the error on Test3.h go away but the other two include errors stayed.

The current config in settings.json is:

  "UEIntellisenseFixes.enableFixes": true,
    "UEIntellisenseFixes.cppStandard": "c++17",
    "C_Cpp.default.intelliSenseMode": "macos-clang-x64",
    "workbench.editor.untitled.hint": "hidden",
    "UEIntellisenseFixes.compiler.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
    "C_Cpp.loggingLevel": "Debug",
    "UEIntellisenseFixes.compiler.strictPath": true,

Any ideas?

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

Ok, so it appears that I managed to find a stable configuration.

I removed the strict flag and left the compilerPath in your extension blank and restarted VSCode.
I checked and it was auto-completed with:
"UEIntellisenseFixes.compiler.path": "/usr/bin/clang",
So far no errors. The output of your extension is as follows:

Extension "UE Intellisense Fixes" 3.3.0 is now active!

Found Unreal Engine v5.0.3

Fixing compiler path in c_cpp_properties.json.
Auto updating extension's compiler setting to /usr/bin/clang
End fix c_cpp_properties compiler path.

Fixing compiler paths in compile commands.
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/usr/bin/clang" @/Users/XXXXXX/CIS/Projects/UE5/Test3/.vscode/compileCommands_Test3/Test3.206.rsp
Compile Command Object wasn't modifed. Will not write file.

I have no idea why it doesn't like "UEIntellisenseFixes.compiler.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++".

Any ideas what's happening?

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

Seems like the project reset isn't working properly. It still has the /usr/bin/clang from the previous time.

Would it be possible to create a new project and see what compiler Unreal chooses for the compile commands (by checking extension log)?

(remember to leave the strict setting unchecked)

I'm also going to update my guide today for different ways to reset your project. Maybe one won't be broken. It'll be funny if it turns out your reset isn't broken and Unreal chooses usr/bin/clang for the compiler.

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022 via email

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

Ok, so I created a new project and let it do its thing. It seems that Unreal is using /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++. However, that gives a lot of errors! See extension output below and screenshot.

Searching for *.uproject file...
Searching with fast-glob found nothing. (Sometimes isn't bug)
*.uproject file was found!

Extension "UE Intellisense Fixes" 3.3.0 is now active!

Found Unreal Engine v5.0.3

Fixing compiler path in c_cpp_properties.json.
End fix c_cpp_properties compiler path.

Fixing compiler paths in compile commands.
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @/Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_MyProject2/MyProject2.204.rsp
File write: /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_MyProject2.json
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @/Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_Default/MyProject2.204.rsp
File write: /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_Default.json
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @'/Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_MyProject2/MyProject2.204.rsp'
File write: /Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_MyProject2.json
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @'/Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_Default/MyProject2.204.rsp'
File write: /Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_Default.json
Done fixing compiler paths.

Fixing invalid paths in response files.
MyProject2.204: Fixed paths count(50), Unfixed paths count(0)
MyProject2.204: Fixed paths count(50), Unfixed paths count(0)
End fixing invalid paths in response files.

Fixing *.generated.h files!
Searching with fast-glob found nothing. (Sometimes isn't bug)
Correct *.generated.h files are found! Note: This extension doesn't test if all *.generated.h files have been created.
For Intellisense, you'll need to Build any newly created project files with the 'Editor' suffix config (e.g. MyProjectNameEditor (platform) Development Build).
All response files have the correct *.generated.h path!
End fixing *.generated.h

Fixing missing compile command files.
No missing file paths found. No fixes needed.
No missing file paths found. No fixes needed.
End fix missing compile commands.

Warning about Public/Private directory
Searching with fast-glob found nothing. (Sometimes isn't bug)
Searching with fast-glob found nothing. (Sometimes isn't bug)
You do not have this directory structure so no warning needed.
End warn Public/Private Directory

Attempting to fix UE workspace(Add empty tag parser).
UE's tag parser includes are set to empty array for performance.
The setting limitSymbolsToIncludedHeaders is already set to true.
End fix UE workspace(Add empty tag parser).

Attempting to fix wrong cppStandard.
Info : UE4 should be default c++14 (it can be c++17 with some special configuration)
Info : UE5 should be c++17
Current VSCode/cpptools cppStandard is:  (Can be blank)
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
MAIN workspace c_cpp_properties.json's cppStandard is already set.
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
MAIN workspace c_cpp_properties.json's cppStandard is already set.
Current VSCode/cpptools cppStandard is:  (Can be blank)
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
UE workspace c_cpp_properties.json's cppStandard is already set.
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
UE workspace c_cpp_properties.json's cppStandard is already set.
End fix wrong cppStandard.

Fixing launch.json.

Attempting to fix the json of launch.json...
There was nothing to fix!
End fix launch.json.

Start fix wrong intellisense mode
Cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Didn't need to set intellisenseMode.
End fix wrong intellisense mode.

Attempting to fix UE workspace optimization.
Optimization of UE is disabled.
End fix UE optimization.


Writing /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/c_cpp_properties.json to file.

Writing /Users/Shared/Epic Games/UE_5.0/.vscode/c_cpp_properties.json to file.

*** Number of error messages: 0
*** Number of warning messages: 0
If you get any errors you can try restarting VSCode to check if they've been fixed.

Extension is done.

Screenshot 2022-09-01 at 17 23 31

I don't know why, but the only way to get it to not fail is to use usr/bin/clang. It makes no sense!

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

Temporarily you can go into the path setting of the extension. It should now have to full xcode/clang++ path there.

Remove the ++ from the path and enable strict.

Restart VSCode and see if the errors go away with the new project. Enabling strict copies the path setting to your compile commands file overwriting the compiler choice that Unreal chose.

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

I'm wondering if this is a version issue?

Unreal requires specific XCode version for developing. It's XCode 12.4 for Mac development on UE5. It's weird because I thought after the release of 5.0.2 it required XCode 13 but it says only IOS projects require that.

https://docs.unrealengine.com/5.0/en-US/hardware-and-software-specifications-for-unreal-engine/

Do you know what version you have?

I know diffferent clang or xcode versions can cause problems. On Windows I can't use clang 14 to compile because it has a new warning and Unreal treats warnings as errros. I had to use clang 13 to compile on Windows.

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

So, I did that and the errors keep on coming back. However, going to definition (F12) works!
I checked XCode and I have 13.4.1. I am planning on deploying to iOS so I had to upgrade to whatever the latest version was.

I wonder why usr/bin/clang works though.

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

When you Build your project you're building with with XCode/clang++ so it does work. Pretty strange that Intellisense can't use the same compiler path.

stdlib.h is a system include and there are a lot of issues people have with them and clang. It could be Unreal isn't including something it should be. It also could be VSCode is failing at polling for system includes. Actually I know they auto poll system includes on Windows but with Mac maybe they don't and use what is listed in the compile commands/rsp(response) files.

If you put it back to what works can you check for system includes using my guide?
https://github.com/boocs/Unreal-VSCode-diy-config-check-github

Also feel free to bail and get back to creating Unreal projects lol

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

I am happy to help, however, I will try it tomorrow.

While I have done lots of development experience in Windows, I am totally new to MacOS/iOS. Without your extension, I would have wasted a lot of time trying to figure all this out. Also, kind of keen on understanding how all of these tools are talking to each other!

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

Ah, never mind about that compilerPath being set to "". I tried it on Windows and my Intellisense failed as well.

I wonder how much a cheap mac is that could create UE5 projects? lol

@max-cis
Copy link
Author

max-cis commented Sep 1, 2022

Cheap Macs! lol
To be honest, not a fan. Just this project requires a Mac to deploy to iOS.

I noticed that your extension doesn't seem to respect the strict flag. I tried reverting back to /usr/bin/clang and it wrote it over with the long path. However, after overwriting it manually with /usr/bin/clang and resetting the database the errors went away. The C++ extension output mentioned lots of tag parsing though.

Anyway, I will try your guide tomorrow and see if I can extract more info. I'm off to have dinner!
Ta

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

Yeah the tag parser can take 15+ minutes when it first parses your project's symbols. You have to wait for it to finish to use my guide.

There is another command for, the VSCode cpptool extension, logs but I like the real time logs better (I've had the two different logs disagree before)

@boocs
Copy link
Owner

boocs commented Sep 1, 2022

I noticed that your extension doesn't seem to respect the strict flag.

That's just my lazy coding. When you enable the strict flag you have to restart VSCode for it to work ( I guess I should mention that somewhere).

@boocs
Copy link
Owner

boocs commented Sep 2, 2022

I been thinking about that macFrameworkPath setting and thinking maybe this is the bug this entire time. I think for clang++ to work it needs the full absolute path to the system libraries found in the xcode path. Or maybe the relative paths just aren't working for the full Xcode clang++ path.

I found this on stackoverflow:

"macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],

Does your Xcode have a similar path like that?

So I would try:

  • Remove strict setting
  • Make sure project is using full Xcode clang++ path
  • Add the full Xcode System/Library/Frameworks path to the "macFrameworkPath" setting(both of them)
  • Restart VSCode

Does it work now?

Also can you search "/Applications/Xcode.app/Contents/Developer/Platforms" for stdlib.h to see where it is located?
Or maybe just search your whole computer to see the different locations it's at.

@max-cis
Copy link
Author

max-cis commented Sep 2, 2022

Ok, gave it a try. Still same errors:

Full output of the C++ debug log here https://pastebin.com/67FeQPuC

The c_cpp_properties.json is as follows:

{
    "configurations": [
        {
            "name": "MyProject2Editor Editor Mac Development (MyProject2)",
            "intelliSenseMode": "clang-x64",
            "macFrameworkPath": [
				"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compileCommands": "/Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_MyProject2.json",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
        },
        {
            "name": "Mac",
            "intelliSenseMode": "clang-x64",
            "macFrameworkPath": [
				"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compileCommands": "/Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_Default.json",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
        }
    ],
    "version": 4
}

and settings.json as follows:

    "UEIntellisenseFixes.enableFixes": true,
    "UEIntellisenseFixes.cppStandard": "c++17",
    "C_Cpp.default.intelliSenseMode": "macos-clang-x64",
    "C_Cpp.loggingLevel": "Debug",
    "UEIntellisenseFixes.compiler.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",

I also used find to search for stdlib.h locations and found several. They are mostly related to different SDKs (didn't know I had more than one) and for different platforms:

/Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h
/System/Volumes/Data/Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h
/System/Volumes/Data/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/DriverKit.platform/Developer/SDKs/DriverKit.sdk/System/DriverKit/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/DriverKit.platform/Developer/SDKs/DriverKit.sdk/System/DriverKit/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/stdlib.h
/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h
/System/Volumes/Data/opt/local/var/macports/sources/rsync.macports.org/macports/release/tarballs/base/vendor/tcl8.5.19/compat/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/DriverKit.platform/Developer/SDKs/DriverKit.sdk/System/DriverKit/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/DriverKit.platform/Developer/SDKs/DriverKit.sdk/System/DriverKit/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/v1/stdlib.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/stdlib.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h
/opt/local/var/macports/sources/rsync.macports.org/macports/release/tarballs/base/vendor/tcl8.5.19/compat/stdlib.h

Also, I followed your guide. The flame is on.

I also tried adding to the macframeworks path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++` instead of the one you suggested as that contains stdlib.h but still gave same errors.

I am surprised that it is not finding it!

@boocs
Copy link
Owner

boocs commented Sep 2, 2022

Thanks for the logs!

Would you be able to post a log file of the same project that's working? (using strict and /usr/bin/clang)

It would be interesting to compare the two logs.

@max-cis
Copy link
Author

max-cis commented Sep 2, 2022 via email

@max-cis
Copy link
Author

max-cis commented Sep 2, 2022

Hey, can you message me your email. Apparently, the log is way longer when using /usr/bin/clang and it is beyond the limit for paste bin.

@boocs
Copy link
Owner

boocs commented Sep 2, 2022

You can cut out all Unreal Paths if that makes it shorter. If it's working but only uses tag parser then that seems weird.

I was looking at Macs and Unreal Engine requirements. The only hard requirement is Using the latest Monterey OS. I saw that I can get a ~$200 late 2014 Mac Mini that can run that OS. I just need to be sure it will be able to create Unreal Projects in UE4/UE5. It doesn't even need to run the engine.

@max-cis
Copy link
Author

max-cis commented Sep 2, 2022

Even though I removed all the Epic ones, it still was over pastebin's limit. So, I split it into two.
I guess that could work. I don't know if you can install Monterey on such an old mac. You should check if they have a limit...

https://pastebin.com/JuBgKDYh

https://pastebin.com/CiNqDCBP

@boocs
Copy link
Owner

boocs commented Sep 2, 2022

There is something weird happening. Both logs say your clang gets detected as version 11

When I use clang 13.0.1 on Windows this is what is shown in logs:

other: --clang_version=130001

Will have to research and look at the logs more.

@max-cis
Copy link
Author

max-cis commented Sep 3, 2022

That's pretty weird! Using which and --version yields the following:

XXX@XXX:~$ which clang
/usr/bin/clang
XXX@XXX:~$ clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
XXX@XXX:~$

@boocs
Copy link
Owner

boocs commented Sep 3, 2022

In your logs it also shows the clang version as 13.1.6 as well so I still think something is wrong with the mac system includes which is why VSCode detects it as version 11.

I was going to rent a cloud Mac to figure this out but if you want to keep going we can.

Here's what I want to try:

  • Full xcode/clang++ path to 13.1.6 in compile commands and compilerPath setting
  • Remove both "macFrameworkPath" settings from your c_cpp_properties.
  • Have c_cpp_properties.json open (this will prevent any Default intellisense logs)
  • Restart VSCode
  • Make sure both Intellisense icons aren't showing
  • Restart VSCode again
  • Post logs

I want to see any mac paths that are included, if any, without the "macFrameworkPath" setting so we get a baseline.

@max-cis
Copy link
Author

max-cis commented Sep 3, 2022

Happy to keep the helping, but today I am fighting another battle and I will be away on Sunday. Will try on Monday :)

@boocs
Copy link
Owner

boocs commented Sep 3, 2022

No problem, I decided to rent the mac anyway because I need to test M1 Macs as well.

@boocs
Copy link
Owner

boocs commented Sep 4, 2022

Don't bother doing it. The framework setting is something else and has nothing to do with includes. VSCode auto includes system paths for Mac just like it does on Windows. So it could be VSCode just isn't including the path to stdlib.h.

Still on going but thought I'd give an update.

@boocs
Copy link
Owner

boocs commented Sep 5, 2022

So this must be a Mac C++ extension bug?

I never even used my extension and just used /usr/bin/clang++ in the compile command file and it worked. Looking at the C++ extension logs shows it including a bunch of paths added from here:

Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/

Also usr/bin/clang works as well.

Even when it works it says clang_version=110000

So basically an easy fix for Unreal 5.0.3. I don't need to change anything on MacOS except the compiler path in the compile commands to /usr/bin/clang++

@max-cis
Copy link
Author

max-cis commented Sep 5, 2022

That's interesting. When I first set up the VSCode in MacOS and used the compiler path it didn't work at all. That's why I went searching and came across your extension.
So, does it work straight up if I set up the compiler path in the c_cpp extension to usr/bin/clang++?

@boocs
Copy link
Owner

boocs commented Sep 5, 2022

Yeah that's because the compiler in the compile commands file overrides the compilerPath setting in c_cpp_properties.

So I I think I'm going to change my extension and have 2 compiler paths. One for c_cpp_properties.json where I have it as an error if it's set. Having it blank will remove the compilerPath setting from c_cpp_properties.

One for compile commands file, compiler path, where I will default it to /usr/bin/clang++ for Macs. Or maybe I just won't auto set it and just explain in the instructions that they should use /usr/bin/clang++

@max-cis
Copy link
Author

max-cis commented Sep 5, 2022

I think it would be good if you have a setting that, if ticked, it sets it, otherwise it leaves it. I would suggest writing in the setting that if not ticked, the user is responsible to set it for Mac to /usr/bin/clang++.
Makes it a lot easier when trying to do a quick deployment. In most cases, you just want to get it working ASAP rather than understanding how all the components interact with one another.

@boocs
Copy link
Owner

boocs commented Sep 6, 2022

I just kept it simple. One path setting no strict setting. If path isn't set it gets pulled from compile command compiler path and set.
Once set it will set both compile commands compiler and compilerPath setting if they are different.

I tested it on my cloud M1 Mac and it works as long as I have the path set to /usr/bin/clang++

@max-cis
Copy link
Author

max-cis commented Sep 7, 2022

Ok, cool! Have you created a new release?

Also, I got two questions you may know about. I cannot find any info atm.

  1. When trying to build from VSCode the debug build, not the GameDebug I get the error:
    ERROR: Targets cannot be built in the Debug configuration with this engine distribution.
    Any idea why? GameDebug does build fine.

  2. Is there any way to ensure that the Unreal Editor is not killed after you stop debugging from VSCode? As it takes a while to restart the Editor. If I have the Editor open, it just opens a copy for debugging. It doesn't attach to the running instance.

Thanks!

@boocs
Copy link
Owner

boocs commented Sep 7, 2022

Yep 3.4.0 is released!

...trying to build from VSCode the debug build

That's normal since you're not using the full source build that option wont work.

the Unreal Editor is not killed after you stop debugging

I don't think so. Sometimes when I'm just testing stuff I don't run debug. I just Build it using one of the VSCode Build Tasks. Once it's done Building successfully I just go to the project folder and double click the *.uproject file to run the project. You must build the 'Editor' suffix build if you want it to load into the Editor.

image

That's the Build task I usually run on Windows. TestFps is my project name.

@max-cis
Copy link
Author

max-cis commented Sep 7, 2022

Oh, ok, so I don't need to worry about the plain debug one.

I guess if I need to inspect variables in VSCode the editor is always killed then. I was hoping I could save the time of restarting the editor each time I hit stop in the debugger. Oh well...

@max-cis
Copy link
Author

max-cis commented Sep 28, 2022

Hey, so it's been a while. I just updated the extension and am getting errors on includes just like before.

Settings are as follows:
"UEIntellisenseFixes.enableFixes": true, "UEIntellisenseFixes.cppStandard": "c++17", "C_Cpp.default.intelliSenseMode": "macos-clang-x64", "workbench.editor.untitled.hint": "hidden", "C_Cpp.loggingLevel": "Debug", "UEIntellisenseFixes.compiler.path": "/usr/bin/clang++",

Also, your extension is reporting some other problems.

'
Found Unreal Engine v5.0.3

** Error **: 0: Couldn't create compileCommands from /Users/lmnicosia/CIS/Projects/UE5/Test3/.vscode/compileCommands_Default.json with key:MAIN! (not an error with UE 4.25.#)

** Error **: Did not create any compile commands with keyMAIN! (not an error with UE 4.25.#)

** Error **: Error in loadCompileCommandsFromWorkspace!

** Error **: This fixable project hasn't been initialized properly and is invalid.

** Error **: Couldn't create file watchers!

*** Number of error messages: 5
*** Number of warning messages: 0
If you get any errors you can try restarting VSCode to check if they've been fixed.

Extension is done.
'

I did update XCode recently... Maybe that broke everything...
Any ideas?

@boocs
Copy link
Owner

boocs commented Sep 28, 2022

What XCode version? I know XCode 14/clang 14.0.0 can cause errors on Mac( and Windows).

Was this a new project you're trying?

@max-cis
Copy link
Author

max-cis commented Sep 28, 2022

Indeed. I am in the process of downgrading. I bloody hate this walled garden of Eden!

@kristianmandrup
Copy link

kristianmandrup commented Oct 28, 2022

What XCode version? I know XCode 14/clang 14.0.0 can cause errors on Mac

Really? What errors? I'm on 14 as well. Ah, I see...

https://stackoverflow.com/questions/73750260/apples-clang-cant-use-with-stdtuple

I don’t code on a Mac but from what I’ve heard it’s advised to not use apple clang and to install clang from homebrew
I'm having the same issue. Apple clang with clib++ (from xcode) appears broken in this regard.

https://embeddedartistry.com/blog/2017/02/24/installing-llvm-clang-on-osx/

You could install brew llvm/clang with:

brew update
brew install llvm

Will print the following info at the end of brew install:

llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"

This will normally install llvm under /usr/local/opt/llvm for not to colide with the apple clang.

$ ls /opt/homebrew/opt/llvm/bin 
clang                       
clang++
...

$ /opt/homebrew/opt/llvm/bin/clang++ --version
Homebrew clang version 15.0.3
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

To work with CMake

You can either set /usr/local/opt/llvm/bin in front of PATH or set CC and CXX environment variables appropriately.

On my machine I have compiled the newest LLVM from sources , installed it under /usr/local/opt/myllvm and set CC/CXX to clang/clang++.

See https://cmake.org/cmake/help/latest/envvar/CXX.html

Perhaps another option:

https://code.visualstudio.com/docs/cpp/config-clang-mac

The first time you run your program, the C++ extension creates tasks.json, which you'll find in your project's .vscode folder. tasks.json stores build configurations.

Your new tasks.json file should look similar to the JSON below:
See https://go.microsoft.com/fwlink/?LinkId=733558 for the documentation about the tasks.json format

{
  
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-std=c++17",
        "-stdlib=libc++",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ]
}

Change to sth similar to the following (see https://discourse.llvm.org/t/switch-from-apple-clang-to-homebrew-clang-in-vs-code-configuration/63314)

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: clang build active file",
			"command": "/usr/local/Cellar/llvm/13.0.1_1/bin/clang",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
                         "detail": "Task generated by Debugger."
                    }
          ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants