Click here to Skip to main content
15,877,573 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every body :
i have been programming in c++ more than a year ,all of them were on visual studio 2010,
so i started using linux from 2 years bt never tried to program on it and here we go, i tried to program c++ on it , but i didnt know how to do it , so
1) how to include libraries on it
2) how to add libraries on it like boost and include them ?
3)how to configure and make install for .cpp files, and how to do .exe files using linux?
by the way Dont tell me about IDEs like eclipse and geany , i want to learn the native way
also i am using now opensuse 12.3
please help
thank you .
enhzflep 4-Apr-13 17:35pm    
And when you get tired of 'coding' makefiles, one of two things will be true.
1) You will have learned how to use and create makefiles
2) You'll be interested in an IDE. Geany sucks, Eclipse runs like 2°C honey. CodeBlocks is a good IDE.

As to your questions:
1) You don't 'include' libraries, you link them
2) See answer 1 _AND_ see the output of the cmd "g++ --help" and "ld --help"
That is to say, you 'include' your header files as you've do doubt already done in other c/cpp/h/hpp files.
You then use the "-l putLibNameHere.ext" switch for ld(g++) when linking to link all of the libraries that you need.

Here's the 3 commands that Code:Blocks (windows) sends when building an example project I have.

mingw32-g++.exe -Wall -fexceptions -O2 -I"C:\Program Files (x86)\CodeBlocks\MinGW\include" -c C:\Users\enhzflep\Documents\code\myCOM\myCOM.cpp -o obj\Release\myCOM\myCOM.o

mingw32-g++.exe -Wall -fexceptions -O2 -I"C:\Program Files (x86)\CodeBlocks\MinGW\include" -c C:\Users\enhzflep\Documents\code\excelAutomate\main.cpp -o obj\Release\excelAutomate\main.o

mingw32-g++.exe -o bin\Release\excelAutomate.exe obj\Release\myCOM\myCOM.o obj\Release\excelAutomate\main.o -s -lole32 -loleaut32
nv3 4-Apr-13 17:38pm    
Just read the documentation that comes with Linux. Many things you might be taking for granted in Visual Studio are not available or just different in Linux. So a lot of reading will give you a better start.

(I'm no linux expert)

There should be a "package" of some sort to install the BOOST libraries on your linux system; or download the stuff from and "configure" it to build and setup the libraries. (read the README files for complete instructions).

If you do not want to use and IDE you will need to learn to use and create a makefile[^]; for simple projects it is easy, for complex projects it can be more difficult.

Also learn the different GCC and G+++ compiler and linker switches to add include path and library path.
Share this answer
OmarSH 4-Apr-13 16:37pm    
thanks for replay but i am not talking about how to install boost libraries i am talking about how to include all libraries
Garth J Lancaster 4-Apr-13 17:03pm    
as per Maximilien's response - 'makefile'(s) , learn how to write them ...
Sergey Alexandrovich Kryukov 4-Apr-13 17:40pm    
Good points, a 5. I have an additional idea for development in C++ on Linux, please see my answer.
If most of your experience is based on Microsoft and Visual Studio, this IDE very close to Visual Studio can help you a lot:[^],[^].


As to boost libraries, I would strongly recommend to download its source and build with your solution. Please see:[^].

On the page referenced above, you can see the Subversion (SVN) command.

This is the Subversion repository:[^].

Subversion is included in code repository for most Linux distro, but not preinstalled by default. Please see:[^],[^].

Share this answer
Matthew Faithfull 4-Apr-13 17:54pm    
Yes. Source control is especially critical in the open source world, great links. +5.
Sergey Alexandrovich Kryukov 4-Apr-13 17:57pm    
I agree with you, but in this case, it was merely an advice on how to get boost; other code bases may require git and more. :-)
Thank you, Matthew.
If you want to do things the 'native' way on Linux that approximates to the GNU way.
To do the things you mentioned you first need to understand make.
Make is the tool that builds and potentially installs the software ( Linux software is usually distributed as source to be built, in the GNU mindset )

The make tool processes a hierarchy of so called 'make files' which are essentially declarative scripts in each folder of the directory tree of your source, describing how to construct one thing from another. The .cpp files that go to make up a .a static library, the .a static libraries that go to make up an executable (no extension for executables) or the file moves and and other commands that go to make up an installation.

Make files (default name Makefile) are written in Make language which has no official name, syntax, grammar or as far as I can tell any 'proper' documentation, so start with man make and move directly to web based tutorials.

Make itself forms part of a group of tools known as the 'autotools' package, zypper install autotools will probably tell you these are already present. Autotools includes scripts and binaries like automake and autoconf which make generating, maintaining and executing make either easier or more complex depending on how well you understand them. The key component of the output they help you produce is the configure script which is a Bash script in the endlessly unspeakable Bash scripting language. The configure script is the 'portable' bootstrap part of the build and install process which uses other scripts to analyse the host system, its capabilities and "brain damage" as certain GNU developers like to call things done differently. Configure also generates or partially generates the Makefiles in a full Autotools scenario and can even be used to rewrite chunks of the source code to target them at the host system's configuration using any of the 'standard' Unix tools, grep, sed etc.
The end result is you ship your source with the scripts generated by autotools and your hard work. The user then does something similar to the following.

make ( or make check )
make install

Remember it is compulsory never to instruct the user where any file should be installed or what the current folder should be when they type the above or any other commands. This prevents all the uninitiated from ever building or installing your software removing all the problems with Noobs and Plebs in one go.
If you fail to do this and provide software with full instructions that any idiot can actually use you will be shunned forever and your populist and unseemly output will be barred from all major repositories. This is the GNU law. I've already been extradited from the Linux world for even writing it down so I no longer care about the consequences of telling you.

( Some people think I am slightly cynical about Linux. I couldn't possibly comment )
Share this answer
Sergey Alexandrovich Kryukov 4-Apr-13 17:49pm    
Useful detail, a 5.
I suggested some additional advice good for Linux C++ development based on Visual Studio experience, please see.
nv3 4-Apr-13 17:57pm    
+5 to both of you. Matthew, I had to smile at your last paragraph :-)
Sergey Alexandrovich Kryukov 4-Apr-13 18:00pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900