c++ - Build systems in Sublime Text, Windows 8 - c++

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! :)

Related

Compiling C++ project from powershell is not working

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

Sublime Text can't find external C++ libraries

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.

Build systems in Sublime Text

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

Alternative IDE for Arduino

Is there some alternative IDE for developing for Adruino
I tried to use Eclipe and Arduino IDE, but i am fan of Sublime Text.
So, can i use it for programming for Arduino or Seeeduino in Linux?
I mean i must download some libraries and plugged in to my source code?
I use a make file, to compile and upload programs to Arduino. You can use any IDE you like (sublime Text in your case and vim in my case)
make upload
make screen # to view the serial monitor
You could use AVR Studio http://www.atmel.com/microsite/atmel_studio6/
Here is a tutorial on to use it with Arduino:
http://www.engblaze.com/tutorial-using-avr-studio-5-with-arduino-projects/
Use whatever editor you feel like and build/upload from the command line. Personally, I use arscons to pull this off. You'll need SCons, of course. Building is as simple as running
$ scons
$ scons upload
at the command line. There are a lot of other options in the SConstruct file provided by the arscons project, such as specifying the location for extra libraries; the type of Arduino you're building for; and which USB port you're plugged into. I wasn't able to get wireless programming for an Arduino Fio working with it, but it works great with the Arduino Mega and Uno.
As others have pointed out, you can use Arduino with any IDE if you set up the toolchain properly. If you're looking for a list of possibilities, as well as documentation on how to start on specific platforms, check out the Development Tools section of the Arduino Playground.
To use with Sublime Text, you could adapt one of the existing command-line build scripts to work with Sublime's build system.

How do you run programs through TextWrangler?

I have just started to get experiment with C++ on my MacBook Pro, and am very new to it all. Through research, a few different people have suggested to use TextWrangler for writing the code. I have put together some of the code that the beginning of a tutorial has given me, but I am now unsure how to run it through TextWrangler. I know that you are supposed to compile it first, but that is mostly where I'm stuck. I have downloaded Xcode so I have gcc, but I don't know where to go from there. And after I have compiled it, is there a simple way to run the file? Like I said, I am very new to all of this and may be looking at it in the wrong way.
TextWrangler is only a text editor, you still need a compiler to compile your code and then you need to run your code.
Xcode (which is an IDE) does all that for you so the confusion is understandable.
for now opening a terminal and doing g++ filename.cpp to compile and ./a.out to run your program will get you going. But you really have to learn to use a IDE or how to write a makefile.