I'm just beginning to learn programming (on C++ and Python), and by beginning I mean total beginning ("hello world" beginning...). Not wanting to use multiple IDE's, I would like to be able to code and build–simple–programs with my text editor, Sublime Text 2. Could someone indicate me, with a step-by-step tutorial, how to implement C++ and Python compiling and executing capabilities in Sublime Text.
I've searched Sublime Text build systems on the site, but the answers are very specific and can't help a rookie like me (but they'll probably help me later).
Thanks
Sublime Text 2 already comes with scripts for building and running Python and C++ programs.
Simply press Cmd+B (or Ctrl+B on Windows & Linux) when a .py or .cpp file is open. The Python file will automatically execute and show the result in the built in console.
For C++, you need to press Cmd+Shift+B (Ctrl+Shift+B on Windows & Linux) to run it after building.
You need to have Python installed (get it here for Windows), and also a C++ compiler. The build system for C++ tries to call g++ by default (get it here for Windows. Remember to select the C++ compiler when installing!).
You will need to add the directories to path (c:\python32\ or similar for python, c:\mingw\bin or similar for the C++ compiler).
On windows, you may experience problems running the C++ programs (it tries to use bash). But Ctrl+B builds the program, and you can then use a command line to run it. Python works flawlessly on Windows.
windows(install minigw, python2.7 and added to the system path)
cpp:
build: ctrl+b
run: ctrl+shift+b
python:
build and run: ctrl+b
you may try to learn the the .sublime-build files in your Tools -> Build system -> New build system
So, you don't want to use an IDE but then you want IDE features from a text editor? :)
Most people who use a text editor for writing code use terminal to build and run the code.
So, for C++, the instructions are:
make (or gcc myprogram.c)
./myprogram
for a Python program, it's even simpler:
python ./myprogram.py
If you're not comfortable with terminal, then you probably need an IDE.
for c++ I actually made sublime to produce colorful error messages which are easier to read and you can also click on the errors which takes you to the file with the error.
You can look at how I modified the build to do what I wanted in here
Related
I am programming a chess engine with 2 friends and it is getting very strong (above 3000 Elo).
We have written the code in C++ and compile using make. For some reason the normal installer for MinGW did not do what it was supposed to so I went with msys2 and installed all the requires packages using msys2.
I am not familiar with compiling C++ under windows and here is the problem:
When I compile the program using the Git Bash or powershell, it compiles nicely (except for a few warnings) using: make native
The issue is the way I need to execute the program:
It does not work if I run using powershell or cmd
It does not work if I double click it (see the error message below)
It does only work if invoked from a bash
If you are not familiar with german, this is a rough translation:
The procedure entry point "..." was not found in the DLL "..."
We have provided a makefile which can build different versions (native, release (for multiple hardwares)). Running a non-native version like Koivisto_3.9-x64-windows-popcnt-avx.exe does run by simply double clicking it.
Also the file sizes are very different:
native: 600kb
non-native: 3100kb
The entire project is on github: Koivisto Chess Engine
And the makefile can be found here: Makefile
I wonder why there seems to be that difference and why the native version only runs within a bash. I am very happy if someone could explain this behaviour to me and potentially even tell me a way to fix this.
I am very happy for any advice!
Greetings,
Finn
I've been looking for an answer to this for about a week now, but I can't find one anywhere. I'm using openFrameworks with Sublime Text on Windows 8, and I've installed MinGW and added it to the path. I've also installed SublimeClang and added this to my SublimeClang User Settings:
{
"options": [
"-I/laura/openFrameworks/libs/**",
"-I/laura/openFrameworks/addons/**"
]
}
The error I'm getting is:
/laura/openFrameworks/apps/myApps/mySketch/src/ofApp.h:3:10:
fatal error: 'ofMain.h' file not found
#include "ofMain.h"
^
1 error generated.
[Finished in 0.1s with exit code 1]
So I don't know if it's a SublimeClang problem or a Sublime problem or a Windows problem, but I'm also new to C++ and don't entirely understand how it builds or finds things. Do I have to addopenFrameworks/libs to the path too or something?
Thanks
NB: Sublime text is an editor. It doesn't have a dedicated build system, or any language integration per se. It just provides convenient ways to call external Build systems via hotkeys (CTRL + B)
Your problem is with the Build system.
Sublime Text 2's default build system for c++ is just calling g++ in command line.
That is sufficient for Hello World, but to build an application that leverages 3rd party libraries, you need an actual Build system, such as make.
Sublime text has a default support for make (you just select the make options in Tools/Build Systems)
The problem with make is that you need to write your own makefile, which is quite beyond the scope of your c++ knowledge apparently (don't take this bad)
You have 3 options in my opinion :
Learn to write makefiles and use Sublime text (with make Build system option or make from the command line)
Use some other (simpler and nicer) build system built on top of make such as CMake. There is a package CMake (that provides syntax highlighting for CMake language) and another CMake-snippets, that provides snippets (prototypes) for the most common operations.
Switch from Sublime text to an IDE. Since you are on windows I suggest QtCreator or Visual Studio Express. I prefer Qt Creator. The good thing about Qt Creator is that it provides its own Build system (qmake) that is very well integrated with the editor, and very noob friendly.
Of course you will learn exponentially more going the 1 or 2nd options, and you'll be up and running in 5 minutes with the 3rd. Your call.
Note that if you want to become a pro c++ developper you will have to learn about Build Systems eventually.
I have a C++ project that is called in Python (via boost-python) and I want to debug the C++ code from python process. How can I do that? In Windows with Visual Studio I can use the functionality attach to process. How to achieve the same in Eclipse?
Thanks
For me it works great just adding a debug configuration in C/C++ for the program /usr/bin/python (or whatever search path you have to the python interpreter) and then put the python program you want to run as the arguments. Put the breakpoints you want in the C-code and you should be all set for running the debug configuration and opening the debug perspective.
If it still does not work you may also check that you are using Legacy (or Standard) Process Launcher. For some reason the GDB process launcher does not seem to work here.
I'm just beginning to learn programming (on C++), and by beginning I mean total beginning ("hello world" beginning...). Not wanting to use multiple IDE's, I would like to be able to code and build–simple–programs with my text editor, Sublime Text 2. Could someone indicate me, with a step-by-step tutorial, how to implement C++ compiling and executing capabilities in Sublime Text.
I've searched Sublime Text build systems on the site, but the answers are very specific and can't help a rookie like me (but they'll probably help me later).
Thanks
Sublime Text 2 will allow you to build .cpp files within the application, but you must have the GNU c++ compiler installed on your machine and defined on your path in order for it to work.
The following link provides a version of g++ for you to use and has detailed instructions for doing this
http://www.claremontmckenna.edu/pages/faculty/alee/g++/g++.html
once youve installed g++ you'll be able to build your .cpp file and run it from with in sublime text 2.
Happy coding! :)
I've been programming on windows for about three months now and when my computer finally died I bought a mac. I'm really happy with it except I can't figure out how to run my c++ programs.
On windows it would open up in command prompt so I figured it would do the same thing except with terminal.
After I write my programs (in Xcode) I can compile them and it'll tell me if there are syntax errors but the run and run related buttons are all Grey and unusable.
It's incredibly annoying that I can't see how the program that I put 4 hours into runs and even more annoying that I don't know if I've made a runtime error. Someone please help.
Thank you very much, James
Assuming that you're trying to write a program that you interact with on the command line, you want to create a "Command Line Tool" project, found under "Application" in the Mac OS X section of the New Project dialog. Choose "C++ stdc++" from the "Type" dropdown, as well. This will give you a main.cpp that should look familiar to you, with a "Hello, World!" sample.
Note that when you Run this program, it might appear to do nothing - You need to open the Console (from the Run menu, or shift+command+R) to see your output.
Xcode deals in projects. If you're just opening the source file, there is no project. Create a project with the files in it and Xcode should let you run it.
Alternately, you can just use G++ on the command line to compile your files and run the resulting executable there.
Try compiling from the terminal as stated above. The a.out file should be created, and should run as long as Xcode has been installed. It should work fine from the terminal, and point out any errors in the compiler's output.
To runs the a.out file, ensure you are in the files directory in terminal and type ./a.out