Thursday, December 26, 2013

Add -pthread flag for C++ build in Sublime Text 2

  1. In Sublime Text 2, go to "Preferences -> Browse packages..".
  2. Inside C++ directory, find the "C++.sublime-build" and open it.
  3. Use the following:
    {
     "cmd": ["g++", "${file}", "-pthread","-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++ '${file}' -pthread -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
    }]
     }