Unable to create C ++ program using Sublime Text 2

I think that many of you use or use the Sublime Text 2 editor. I have a strange error: C ++ programs cannot be built.

My C++.sublime-build :

 { "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"], "working_dir": "${file_path}", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] } ] } 

I found that when the cmd array contains ANY substituted expressions such as ${file} or $file , the assembly does not start. Otherwise, it will begin.

It does not matter to the compiler. When I tried "cmd": ["notify-osd", "$file"] , this did not work; but with "cmd": ["notify-osd", "sometexthere"] it worked.

Manual compilation is working correctly.

My program:

 #include <iostream> int main() { std::cout << "Hello World"; } 

I am using Ubuntu 12.04, 32bit. Sublime Editor version: 2.0.1.

If this is not the place where I could ask this question, please tell me which one.

+6
source share
3 answers

Edit your C ++ file. sublime-build ... works like a charm.

 { "cmd": ["g++", "-Wall", "-Wextra", "-pedantic", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "g++ -Wall -Wextra -pedantic -std=c++11 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] } ] } 
+7
source

I can provide a workaround for this problem: use make files. Sublime Text 2 can run makefiles to compile C ++ for you.

You will be more likely to get a better answer to this question by asking on the Sublime forums (http://www.sublimetext.com/forum/). Even there, they would probably be interested in knowing “how” this does not work (ie. If nothing happens when you press “Build”, you can specify this).

+1
source

It took me a few hours for the C ++ compilation to work on Sublime Text, and I still have minor problems (for example, the fact that Sublime Text cannot obviously execute the program in an external window / console).

Here is my configuration file:

 { "cmd": ["C:\\MinGW\\bin\\mingw32-g++.exe", "-Wall", "-time", "$file", "-o", "$file_base_name"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "working_dir": "${project_path:${folder}}", "selector": "source.c", "shell": true, "encoding": "latin1" } 

(be sure to replace the encoding with utf8 if the compiler does not work)

Also, add the MinGW bin folder to the OS Path variable (find the "environment variable" in the Start menu, and then find the Path variable).

0
source

Source: https://habr.com/ru/post/920488/


All Articles