Sublime Forum

Issue with capture Clang error messages for C++

#1

This is my build system

{
	"file_regex": "^([^:]+):([0-9]+):([0-9]+)? error: (.+)$",
	"cmd": "clang-cl -Od -MTd -fp:fast -fp:except- -nologo -GR- -EHa- -Oi -WX -W4 -wd4505 -wd4201 -wd4100 -wd4189 -wd4324 -DINTERNAL=1 -DSLOW=1 -DWIN32=1 -FC -Z7 -GS- -Wno-invalid-token-paste -Wno-null-dereference -Wno-unused-variable -Wno-microsoft-cast -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -m64 C:/Users/J/Documents/project/code/win32_jesse.cpp",
    "working_dir": "${file_path}",
    "selector": "source.h, source.cpp"
}

And yet, ST3 doesn’t point out the error in the code view. ST isn’t providing any real feedback as to what is happening (or lack there of). Any ideas?

0 Likes

#2

If I understand your right, you struggle capturing the filename and line in the result, right?

You can use sublime.log_result_regex(True) (in the console: View → Show console). (never used it before)

Try to use http://regex101.com to make your regex. If you give me the error message, I could try doing it for you…

And, this regex, doesn’t work:

^([^:]+):([0-9]+):([0-9]+)? error: (.+)$

trying to match against:

C:/Users/J/Documents

^: the beginning. OK
([^:]+): anything that is not :, as many time as possible, at least once. It only matches the C. You shouldn’t capture it
:: Matches the :
([0-9]+): matches any number, at least once: nothing’s found, stops here.

0 Likes

#3

I looked on Google for example of clang messages, and now I understand your regex. So, the problem is maybe your compiler, which returns a weird message.

But again, you can make an other regex for it (or again, ask me, I’d love doing it for you)

From the error message you’ve shown in the picture, here’s the regex I’ve come out with:

([^\n]+?\.cpp)\((\d+),(\d+)\) : error: ([^\n]+).

Because the .sublime-build is written in JSON, you’ll need to escape the backslashes:

([^\\n]+?\\.cpp)\\((\\d+),(\\d+)\\) : error: ([^\\n]+)

0 Likes

#4

Thanks math2001. I tried your regex and ST3 didn’t respond to them. :confused:

The following "file_regex": "^ *([A-z]:.*)[(]([0-9]+)(?:[:][0-9]+)*[)]", does allow ST3 to display microsoft’s compiler output, but not clang.

I was following this as a guide, as this setup works for another person I know : https://gist.github.com/gingerBill/ae33515cad4918d8db7796426c67ff61

0 Likes

#5

Can you give me the output when there’s an error message?

0 Likes

#6

C:\Users\J\Documents\project\code\win32_jesse.cpp(772,70) : error: expected ';' after expression AssetClock += Win32GetSecondsElapsed(LastCounter, EndCounter) ^ ; 1 error generated.

0 Likes

#7

That’s weird that it doesn’t work, have a look here. It matches it. Make you take the second regex (this one [^\\n]+?\\.cpp)\\((\\d+),(\\d+)\\) : error: ([^\\n]+)).

Just in case, you have to replace this ^ *([A-z]:.*)[(]([0-9]+)(?:[:][0-9]+)*[)] by the regex I just gave you in your build system.

BTW, when you post multi-line code, do this:

```
your code
goes here
```
0 Likes

#8

Thanks for your help. Still no luck though. :frowning:

0 Likes

#9

Let’s make things clear:

  • the problem is that you don’t see any error message under the error, right? Does it work in other language?
  • if you press f4, does it take you to the error line?
  • are you sure you’re building with the right build system (ctrl+shift+b to choose)?

In the picture i’ve seen that there is weird (double?) spaces before the word error. Here’s a more “acceptive” regex:

([^\n]+?\.cpp)\((\d+),(\d+)\) *: *error: *([^\n]+)

The one you have to put in your build system:

([^\\n]+?\\.cpp)\\((\\d+),(\\d+)\\) *: *error: *([^\\n]+)

1 Like

#10

The issue is that only under Clang do I not see error messages caught by ST3. They work with Microsoft’s compiler.

f4 does not take me to Clang’s error line or anything.

Yes I’m 100% positive my build system is being called.

Your new regex doesn’t work either. :<

Thanks for the help!

0 Likes

#11

That’s really weird because it works for me (I emulate the error with a python program, and ST catches the error).

Are you sure you have only 1 build system named Shards?

To exactly this.

  1. Tools → Build With
  2. Pick Shards
  3. Copy the entire output. (ctrl+a, and then ctrl+c)

Now, paste the output in here between this: ```, like so

```
paste your code between those two "fences"
```

rebuild again, look in the status bar, you should see Build finish. Tell me if it’s the case.

0 Likes