Saturday, October 14, 2017

How to build customize C++ system for Sublime text 3 for Windows?




# Why sublime-text?

    # Because, it is lightweight, portable, and runs on Win/Linux/MacOS and less than 10 megabytes.
    # it is more flexible and extensible.
    # You can turn your Sublime-text editor into a FULL featured IDE.
    # I really use it for C/C++/HTML/JS/CSS/Python/Java, and it is great.
    # Sublime-Text Editor is more real, because it allows you to customize almost everything.
    # For Compiled languages, you can use pre-built BUILD SYSTEM or create your own.
    # Snippet, that is a great idea and that would be great if you learn, how to write snippet and use them.

# Why we are here?
 # What is Build-system in Sublime-Text Editor?

        # Build-system allows you to write and build programs directly ( Just hit, CTRL+b ) and if you want to run build binary ( Just hit, SHIFT+CTRL+b )


    # What about Pre-built BUILD SYSTEM for C++??
        # That is great, but we want some more functionality ( I want to pass some command line parameters ) , this is why we want to write our own Custom BUILD SYSTEM for C++.

  #How can i get a sublime text 3 to ready for building of C++??

  
  1. at first install the latest version of sublime text :  download link (don't install portable version ,always install other one for your OS)
 2. install the software and open it.
 3. to set up new customize c++ build :
    tools > build system >new build system
     you will get like this window:



4. then paste this code to this window and save it as  c++11.sublime-build



{

"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++,source.cpp",

"variants":

[
    {
        "name": "Run",
        "shell_cmd": "g++ -std=c++14 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
    }
]

}


5. you have to download a compiler of C/C++ for your OS (processor : 64/32 bit )

download  link :  Mingw  
and  install it . 
If you have already install a c++ IDE (code blocks , devc++ etc), then you don't need to install  Mingw  
(Because sublime text is an editor not an IDE)

6. Then set environment variable for it . If you had a c++ IDE  (code blocks , devc++ etc)  ,which is previously installed ,then set the environment variable for it:


Environment variable set: 


  • go for   ->   Control Panel\System and Security\System\advanced system settings\environment variable
  • System variable\path   and edit path  and paste path like as: (C:\Program Files (x86)\CodeBlocks\MinGW\bin;) (you have to set path upto bin)



7.  write a C++ code and select build system for it :  you will select c++11 





8.  then create a input .txt file  and output  .txt file  for your  c++  code  and set input to the input.txt and tap    ctrl+shift+b and you will get output to the output.txt file.




9. Now your sublime text is ready to build any c++ code  ,just  by  clicking ctrl+b  and get output to the output.txt  from input.txt 


10. To make multiple layouts (3 windows), go to view > layout > Column 3



11. Now select View->Groups->Max columns: 2.

12. To use indentation----
a) Ctrl+]   -- Indentation
b) Ctrl+[   -- Unindentation


      Happy Coding  !!!

No comments:

Post a Comment