Sublime Forum

Handle a C++11 extension warning

#1

Hello everybody,

First :

  • I’m like a virgin in programming, and more in Sublime Text,

Thus :

  • I’m very sorry if I’m clumsy;

  • I promise to become an expert, mostly by studying the documentation;

  • be nice with me.

The following code is supposed to work (taken on : http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/#cpp11):

but I get “warning: ‘auto’ type specifier is a C++11 extension [-Wc++11-extensions]”.

Would someone be so kind as to help me handle this warning and get my « Hello world! » ?

I use Sublime Text 3.1.1, and OS X 10.11.6.

Thanks a lot.

0 Likes

#2

You can edit your .sublime-build file to add the command-line option -std=c++11 (or -std=c++14), that will make the warning go away.

0 Likes

#3

More precisely…

Click on Tools -> Build System -> New Build System, and paste the following content:

{
    "cmd": ["clang++", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++"
}

Save the file in the directory that is presented to you (your “User” directory).
Now click again on Tools -> Build System and select your build system that you just saved. Then hit B to build your file.

1 Like

#4

I really appreciate the impressive refinement of your second reply, Rwols, but I’m sorry to write that I do not get « Hello world! » :

I have the feeling it’s just a matter of an even more simple edit to do…
Thank you very much already !

0 Likes

#5

The build system presented here simply builds an executable. If you want to actually run that executable, you have a few options. You can change the build system’s cmd key to something like (I haven’t tested this)

"shell_cmd": "clang++ -std=c++11 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"./${file_path}/${file_base_name}\"",

but you will invariably come across the problem where it turns out that ST cannot take input from its output panel. So I advice you to run executables with the Terminal app instead. To do that, open the Terminal app and type the following (without the dollar signs):

$ cd path/to/your/project
$ ./HelloWorld

Another option would be to use the Terminus plugin to run, maybe even build your programs.

1 Like

#6

Using the terminal, I feel I’m getting closer to my computer;
This is very satisfying.

Thanks for this,

Best wishes from France !

1 Like