Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 208
Daniel Sloof Avatar asked Mar 08 '09 04:03

Daniel Sloof


2 Answers

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.

like image 101
MandyK Avatar answered Oct 03 '22 10:10

MandyK


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.
like image 27
Brian Gianforcaro Avatar answered Oct 03 '22 10:10

Brian Gianforcaro