How to configure Vim for C++ development? - c++

I'm learning C++ using Vim as an editor on Windows XP, however I found a issue that I have listed below.
I have downloaded and installed c.vim and it is a essential file, however when I start vim it shows the message C/C++ template file 'C:\Program Files\Vim\vimfiles\c-support/templates/Templates' does not exist or is not readable, How do i fix this problem?
How would i make vim compile a C++ STL file?

For your first problem: I suspect that you didn't extract all the files in the archive (that c.vim came in). The c.vim documentation (README.csupport) says:
The subdirectories in the zip archive
cvim.zip mirror the directory
structure which is needed below the
local installation directory
$HOME/.vim/ for LINUX/UNIX
($VIM/vimfiles/ for Windows)
This means that you need to uncompress the entire archive as it is into your vimfiles directory.
There are some other steps to follow, detailed in the documentation.
As for your second issue: you need a Makefile to do that. If you have never done this before, I suggest using cmake to generate a Makefile. You will also need GNU tools for Windows; Cygwin or MinGW are the most popular choices. I haven't use them, it is easier to do all this on some *nix OS :).
When done, use :cd (if you are not in your working directory), and :make. Use :cl to list the compiler output, :cn to jump to the next error. There are some other useful commands for compiling. You might find these resources useful:
StackOverflow: Recommended plugins for C coding
Compiling from Vim
C editing with Vim
Also, I found the Nerd Commenter a very useful companion.
I found that Vim acts somewhat like alien on Windows; it is designed for an *nix-like operating system. I think it is possible to craft a similar environment for it, and use it mostly successfully, but it is so much easier to do on some linux, as it is "instantly home" there.
Anyway, if you wish to stick with Windows, I think you can find a way to accomplish what you want. Good luck.

Download Vim and install to your computer.
Download c.vim and extract to $Vim\vimfiles\
Download MinGW and install to your computer, make sure that you check C++ Compiler at Select Components.
Add C:\MinGW to system Path variable
Edit _vimrc file, add set makeprg=mingw32-make after line behave mswin
Test your Vim with hello world, use !g++ c:\full_path\filename.cpp -o c:\full_path\output.exe.

Related

Considering Autocompletion. How to tell Geany in which directories to look for header files?

I am coming from KDE to XFCE and hence arrive from KDevelop at Geany. I have no plans of using Geany for any compilation stuff, prefering to write my own CMakeLists.txt files. However, what I loved about KDevelop and dearly would have again:
In KDevelop I could "attach" an include-directory to a c++ file meaning that code autocompletion would look for #included headers within that directory and use its content.
For example it was possible to "attach" something like /usr/share/myIncludes/
containing "my_foo.h". Then in the source code of my program I would
#include "my_foo.h"
and henceforth auto-completion would kick in using the contents of "my_foo.h".
I find this surprisingly hard to google. Is there even a feature like that in Geany, and if so, how would one use it?
My Geany is a simple install (geany and geany-common) on a clean (no non-free stuff) Debian System.
Geany is not supporting dynamic parsing of header files due to the performances and resources impact it would have.
However, you can generate a tag file from your headers as described inside manual or maybe use a plugin like geanyctags or projectorganizer (recently rename from gproject) which could help you there
Also you can find tag-files inside the wiki which you can import via the Tools-menu.

Getting a library to work (QuadProg++ )

I'm trying to use the Quadprog++ library (http://quadprog.sourceforge.net/). I don't understand the instructions though.
To build the library simply go through the ./configure; make; make
install cycle.
In order to use it, you will be required to include in your code file
the "Array.hh" header, which contains a handy C++ implementation of
Vector and Matrices.
There are some "configure", and "MakeFile" files, but they have no extension and I have no idea what to do with them. There are also some ".am", ".in" and ".ac" extensions in the folder.
Does this look familiar to anyone? What do I do with this?
(Edit: On Windows.)
This package is built using the autotools. These files you talk to (*.am, *.in...) are because of the tools automake, and autoconf.
Autotools is a de-facto standard in the GNU/Linux world. Not everybody uses it, but if they do you ease the work of package and distribution managers. Actually they should be portable to any POSIX system.
That said, I'm guessing that you are using a non-unix machine, such as Windows, so the configure script is not directly runable in your system. If you insist in keep using Windows, wich you probably will, your options are:
Use MinGW and MSYS to get a minimal build enviroment compatible with autotools.
Use Cygwin and create a POSIX like environment in your Windows.
Create a VS project, add all the source of the library in there, compile and debug the errors they may arise, as if the code had been written by you.
Search for someone that already did the work and distributes a binary DLL, or similar.
(My favourite!) Get a Linux machine, install a cross-compiler environment to build Windows binaries, and do configure --host i686-mingw32 ; make.
This instruction say how can be build an program delivered like a tarball in Linux. To understand take a look on Why always ./configure; make; make install; as 3 separate steps?.
This can be confusing at first, but here you go. Type these in as shown below:
cd <the_directory_with_the_configure_file>
./configure
At this point, a bunch of stuff will roll past on the screen. This is Autoconf running (for more details, see http://www.edwardrosten.com/code/autoconf/index.html)
When it's done, type:
make
This initiates the build process. (To learn more about GNU make, check out Comprehensive gnu make / gcc tutorial). This will cause several build messages to be printed out.
When this is done, type:
sudo make install
You will be asked for the root password. If this is not your own machine (or you do not have superuser access), then contact the person who administers this computer.
If this is your computer, type in the root password and the library should install in /usr/local/lib/ or something similar (watch the screen closely to see where it puts the .so file).
The rest of it (include the .hh file) seems self-explanatory.
Hope that helps!

Installation Script for simple c++ command-line tool, tutorial?

I'm working on a simple command line tool in c++. Half as a fun learning-process thing, and half to distribute to friends/colleagues etc.
I assume the easiest way to make it distributable is just packaging the source code with an installation script---can anyone point me to a good tutorial for setting that up?
In other words, what must a script include to compile the program, put the files in good places*, and make it executable from any directory from the command line?
E.g. I know the compiled binary should go in /usr/local/bin/ , but if I'm writing-to and accessing a text file (for instance), where should that go? What about a file that stores settings/configuration-parameters?
I'm on mac osx, so that would be the starting point, but portability to windows, linux, etc would be great.
You can use CMake to make a cross platform build system, and you can use it's CPack (Wiki here) feature in order to generate binary only packages. First you create a build script that runs and installs on each platform (which CMake makes as easy as can be expected). You then run CPack to generate a package which just includes your binaries.
There is a good tutorial that covers the basic cmake process (including install commands) here.
CMake is generally considered simpler then autoconf (and has better windows support), but each has it's own strengths.
Do not assume that the user installing the program has root access. Prompt, or provide a command-line option, like --install-prefix=/home/user/apps, to specify where to install.
I HATE programs that install shit in /usr/local. If you do that, you'd best wrap it up in an .rpm or .deb or whatever the platform package is so that your app can be cleanly uninstalled.
I would suggest checking out autoconf

C++ development on linux - where do I start?

I decided to leave my windows install behind and am now running Debian as my default OS. I have always coded in Windows and specifically with Visual Studio. I am currently trying to get used to compiling my code under linux.
Although I still have a lot of documentation to read, and don't expect you guys to make it too easy for me, it'd still be nice to get some pointers on where to start. I have some specific questions, but feel free to suggest/recommend anything else regarding the subject.
What are recommended guides on creating a make file, how do I compile from this makefile (do I call g++ myself, do I use 'make'?)
Looking at other linux software, they almost always seem to have a 'configure' file. What exactly does it do? Does it only check if the required libraries are installed or does it more than just checking requirements?
How do I link libraries, and how does this relate to my makefile or g++ parameters? In windows I would compile the library, include some header files, tell my linker what additional lib file to link, and copy a dll file. How exactly does this process work in linux?
Recommendations for code editors? I am currently using nano and I've heard of vim and emacs, but don't know what the benefits of them are over eachother. Are there any others, and why would I consider them over any of the previous three? Note: I am not looking for an IDE.
Any help, links to guides & documentation (preferably those that are aimed at beginners) are very much appreciated!
What are recommended guides on creating a make file, how do I compile from this makefile (do I call g++ myself, do I use 'make'?)
You build from the makefile by invoking "make". And inside your makefile, you compile and link using g++ and ld.
Looking at other linux software, they almost always seem to have a 'configure' file. What exactly does it do? Does it only check if the required libraries are installed or does it more than just checking requirements?
It's a script usually used to set up various things based on the environment being used for building. Sometimes it's just a basic shell script, other times it invokes tools like Autoconf to discover what is available when building. The "configure" script is usually also a place for the user to specify various optional things to be built or excluded, like support for experimental features.
How do I link libraries, and how does this relate to my makefile or g++ parameters? In windows I would compile the library, include some header files, tell my linker what additional lib file to link, and copy a dll file. How exactly does this process work in linux?
ld is the GNU linker. You can invoke it separately (which is what most makefiles will end up doing), or you can have g++ delegate to it. The options you pass to g++ and ld determine where to look for included headers, libraries to link, and how to output the result.
Recommendations for code editors? I am currently using nano and I've heard of vim and emacs, but don't know what the benefits of them are over eachother. Are there any others, and why would I consider them over any of the previous three? Note: I am not looking for an IDE.
Vim and Emacs are very flexible editors that support a whole bunch of different usages. Use whatever feels best to you, though I'd suggest you might want a few minimal things like syntax highlighting.
Just a note to go with MandyK's answers.
Creating make files by hand is usually a very unportable way of building across linux distro's/unix variants. There are many build systems for auto generating make files, building without make files. GNU Autotools, Cmake, Scons, jam, etc.
Also to go more in depth about configure.
Checks available compilers, libraries, system architecture.
Makes sure your system matches the appropriate compatible package list.
Lets you specify command line arguments to specialize your build, install path, option packages etc.
Configure then generates an appropriate Makefile specific to your system.
What are recommended guides on
creating a make file, how do I compile
from this makefile (do I call g++
myself, do I use 'make'?)
I learned how to write makefiles by reading the GNU Make manual.
Looking at other linux software, they
almost always seem to have a
'configure' file. What exactly does it
do? Does it only check if the required
libraries are installed or does it
more than just checking requirements?
The configure file is usually associated with autotools. As the name of the script suggests, it allows you to configure the software. From the perspective of the developer this mostly means setting macros, which determine variables, which libraries are available, and such. It also tests for the availability of libraries. In the end the script generates a GNU Makefile, which you can then use to actually build and install the software.
The GNU build system is only one of many. I don't particularly like the GNU build system as it tends to be slower than others, and generates an ugly Makefile. Some of the more popular ones are CMake, Jam (Boost Jam might be of interest for C++) and waf. Some build systems simply generate Makefiles, while others provide a completely new build system. For simple projects writing a Makefile by hand would be easy, but "dependency checking" (for libraries, etc) would also have to be done manually.
Edit: Brian Gianforcaro also pointed this out.
Your question is a bit too general, but here is what I would recomment:
Editor: vim and emacs are popular. What matters the most, as with most tools, is to master one. I like using vim because vi (its descendant) is available everywhere, but that may not be very relevant, specially if you stay on Linux. Any programming editor is fine.
configure: unless you do big projects, don't bother with it. It is a nightmare to use and debug. It only makes sense if you intend to distribute your project - in that case, read the autobook: http://sources.redhat.com/autobook/. As other said, there are alternatives (cmake, scons, etc...). I am quite familiar with both scons and autotools, but I still use make for small (couple of files) projects.
Concerning shared library: it is almost as windows, except that you link against the shared library directly - there is no .lib vs .dll distinction in Linux. For example. for one library foo with a function foo:
int foo(void)
{
return 1;
}
You would build it as follows:
gcc -fPIC -c foo.c -o foo.o
gcc -shared foo.o -o libfoo.so
A main (of course in real life you put the API in a header file):
int foo(void);
int main(void)
{
foo();
return 0;
}
And then, you link it as:
gcc -c main.c -o main.o
gcc main.o -o main -L. -lfoo
The -L. is here to say that you want the linker to look in the current directory (contrary to windows, this is never done by default in Linux), the -lfoo says to link against the library foo.
So to get you started I will first point you to this guide for makefiles, it also covers some linking stuff too.
It's just a little something my university Computer Science prof gave us I found it to be very clear and concise, very helpful.
And as for an IDE, I use eclipse usually because it handles the makefile as well. Not to mention compile and standard output are right at your fingertips in the program.
It was mainly intended for Java developing, but there is a C/C++ plugin too!
Recommendations for code editors? I am
currently using nano and I've heard of
vim and emacs, but don't know what the
benefits of them are over eachother.
Are there any others, and why would I
consider them over any of the previous
three? Note: I am not looking for an
IDE.
Vi and Emacs are the two quintessential Unix editors; if you are set on using a text editor rather than an IDE, one of them or their derivatives (vim, xemacs, etc) is the way to go. Both support syntax highlighting and all sorts of features, either by default or via extensions. The best part about these editors is the extensibility they offer; emacs via a variety of lisp, and vim via its own scripting language.
I personally use Emacs, so I can't say much about Vim, but you should be able to find lots of information about both online. Emacs has several good tutorials and references, including this one.
EDIT [Dec 2014]: There seems to be a trend of cross-platform and highly extendable editors recently. This could be a good choice if you'd like something less than an IDE, but more graphical than vi/emacs and native-feeling across multiple platforms. I recommend looking at Sublime or Atom; both of these work across Windows/Linux/Mac and have great communities of plugins and themes.
I recommend the book The Art of Unix Programming by ESR. It covers choice of editor, programming language, etc. It also gives a good sense for the mindset behind programming on Unix or Linux.
For editors, you probably want either Vim or Emacs. They are both different and which one is better is more about personal taste than anything else. I use Vim. It is great for quickly moving around the code and making changes. I didn't like Emacs as much but many people do. Emacs is extremely extensible and can be used for everything from a news reader to an ide. Try both and see what you like.
Recommendations for code editors? I am currently using nano and I've heard of vim and emacs, but don't know what the benefits of them are over eachother. Are there any others, and why would I consider them over any of the previous three? Note: I am not looking for an IDE.
If you're using Linux with a window manager (KDE, Gnome, etc.) you could also consider using the standard text editor for your window manager. The main benefit it would have over vim/emacs/nano is that it would seem more familiar to one coming from a Windows environment - an editor written to run on the window manager has a menu bar, file open/save dialogs, undo/redo, and plenty of other neat features that console editors probably can't match. (Though emacs and vim are pretty sophisticated these days, so who knows ;-P)
On KDE (which is what I use) I can recommend KWrite, which is a well-featured but fairly basic text editor with syntax highlighting; or Kate, which is a fancier text editor with some extra features: session management, a builtin terminal panel, automatic invocation of make, and several plugins including a C/C++ symbol viewer. I usually use Kate for my C++ work when I don't want to bother with setting up a full IDE project. (FYI the IDE for KDE is KDevelop)
the space between invoking g++ directly and using an autotools build chain is pretty narrow. Get good at autotools, which is really the closest thing to a 'project' available in the Linux/Open Source world.
For someone coming from Visual Studio, all this commandline stuff might seem arcane and messy.
Before you turn into a bash shell/vim/emacs junkie, try a few GUI based tools first so you have some transition time...
QT 4.5 with its QT Creator mini-IDE. This is the best framework, lightyears ahead of the competition.
Eclipse (C++) - From my experience with this on Windows, I find it's astounding ( This is probably the best Java application ever written )
KDevelop
Anjuta
If you use Delphi, Lazarus/FreePascal is a good alternative.
I'm sure the longhairs will scoff and claim that vim or emacs gives them the best and fastest development environment, but different strokes for different folks. Someone accustomed to an IDE will take some time to switch or may not wish to switch at all.
For all their editing prowess, creating GUI apps is certainly not a job for 80x25 tools.
It takes years to become an expert with the command line side of things, its more of a transformation of worldview than anything else.
As a side note amongst the proper answers here.. In case you wanna hit the ground running as a Windows guy, I'd suggest the fresh new Qt SDK. It will feel like home :-)
I advise using SCons in place of Make, it does the same job but it's easier to use and handle out of the box how to make dynamic libraries, dependencies, etc. Here it is a real life example for a simple prog
env = Environment()
env.Append(CCFLAGS='-Wall')
env.Append(CPPPATH = ['./include/'])
env.MergeFlags('-ljpeg')
env.ParseConfig("sdl-config --cflags --libs")
env.ParseConfig("curl-config --cflags --libs")
env.ParseConfig("pkg-config cairo --cflags --libs")
env.Program('rovio-pilot', Glob('./src/*.cpp'))
As a text editor, I'm happy with JEdit for coding, but it's a matter of taste.

Is there an equivalent of Make on Windows? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I develop on Windows, and I'd like to use beanstalkd. It's only available as a tarball, and I was just wondering if there is some way to easily build it like you can in Linux? I found some ports of gnu make for Windows, but they don't seem to be working. Are the source distributions somehow specific to Linux?
When I try to use mingw32-make it says "Nothing to be done for file". TBH I wasn't sure what to run it on, so I tried the tarball, the directory, and Makefile.in and Makefile.am. They all say the same thing.
Make is available in cygwin, which you can install make via the installer.
The package is called "make", which is under "Devel" category.
I found some ports of gnu make for
Windows, but they don't seem to be
working.
Here are a few ports of GNU tools to Windows:
GnuWin32 - http://gnuwin32.sourceforge.net/summary.html
Gnu Tools for NT - http://www.devhood.com/Tools/tool_details.aspx?tool_id=3
GNU Utilities for Win32 - http://unxutils.sourceforge.net/
I am pretty sure I have used some of the utilities from the unxutils port without problems.
I would also look into using msys with mingw (it also can be found at http://mingw.org) I could try to explain it but I think the description from their page works better
MSYS: A Minimal SYStem providing a POSIX compatible Bourne shell environment, with a small collection of UNIX command line tools. Primarily developed as a means to execute the configure scripts and Makefiles used to build Open Source software, but also useful as a general purpose command line interface to replace Windows cmd.exe.
One bonus of using msys over cygwin is it builds native windows applications rather than having to rely on the cygwin compatibility layer
Most unix source packages require you to run "configure", which reads some info about your system and builds the Makefile - although in the early days of X11, some packages used "xmkmf" to build Makefiles out of IMakefiles. Only after thats done can you run "make" and possibly "make install". From the sound of it, you don't have a Makefile, only the Makefile.in (which is input to configure).
Cygwin is nice, as the previous answer indicated, but it includes a lot more than just make.
I used to use NMake on Windows to build Perl modules. Check it out:
http://johnbokma.com/perl/make-for-windows.html
That's useful for Perl. Looks like there's a general GNU port, too:
http://gnuwin32.sourceforge.net/packages/make.htm
Cygwin and mingw come to mind.
MSVC includes nmake which kind of works on regular makefiles with some tweaking.
The make utility expects to use a file named Makefile. If you just type make, it will find that file automatically. If the makefile has some other name, use the -f option. If you just give the file name without -f, then make will interpret it as the target that it should figure out how to make.
A lot of tools that only come as source assume that you'll use Visual C++ to build on Windows, even if they assume you'll use G++ everywhere else. Look for a Visual C++ makefile; it's usually named Makefile.mak. Then run nmake.
But if you only have files named Makefile.in and Makefile.am, then you don't yet have a makable environment. Makefile.in is one of the inputs to the configure script, which will construct the real makefile and maybe a header or two that are specific to your environment, based on tests that configure runs.
In the end, the package you've downloaded might not really be compilable on Windows. Even under Cygwin, you can expect to have to make a few changes to the source code if it hasn't been written with Windows in mind.
Makefile.in will contain the basics of the final makefile. Back before I knew what I was supposed to do, I simply renamed Makefile.in to Makefile and got pretty far. You can try using that file as a starting point for constructing a real Windows makefile, for whichever compiler target you choose. It will take patience; just keep following the compiler messages until you don't see any more. (And then comes the linker. Hope you don't need too many other libraries!)
Concerning the alternatives, check out this link. As far as your problem with make, you'll have to be a little more specific about the non-working part. What doesn't work, how does it manifest, what error it gives and such.
Let someone else do the hard work. Here's a precompiled beanstalkd 1.4.6 exe.
Decompress the tarball, cd into its topmost directory and type 'make'. Make will pick up the Makefile automatically.