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

35,564

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

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!

Share:
35,564
Daniel Sloof
Author by

Daniel Sloof

Located in the Netherlands. Business owner and developer (mostly Magento) but interested in all aspects of development. I work for Rubic!

Updated on July 09, 2022

Comments

  • Daniel Sloof
    Daniel Sloof almost 2 years

    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!

    • Daniel Sloof
      Daniel Sloof about 15 years
      ps: Should this be community wiki?!
    • Tim Matthews
      Tim Matthews about 15 years
      NO leave as not wiki but all those questions have been asked before.
    • user3341101
      user3341101 about 15 years
      may be this will give some idea.. firstcprograminlinux.blogspot.com
  • Zan Lynx
    Zan Lynx about 15 years
    Using a GUI to build the GUI is great. Then what? Then you dig out vim and emacs! Vim can have renamed six function calls before someone can get the Find/Replace window open and filled out in an IDE.
  • Bjorn
    Bjorn about 15 years
    Scons are a great alternative to Makefiles
  • sharrajesh
    sharrajesh over 10 years
    The book seems to be also available as pdf at catb.org/~esr/writings/taoup/html/graphics/taoup.pdf
  • Tomm P
    Tomm P over 2 years
    "which one is better is more about personal taste " -> "is a matter of religious wars" ;)