C and C++ programming on Ubuntu 11.10
You don't need an IDE to code in C or C++ on Ubuntu. You can use a good editor (like emacs
, which you can configure to suit your needs.).
Some few tips for a newbie:
- Always compile with
-Wall -Wextra
and perhaps even with-Werror -pedantic-errors
Order of arguments to the compiler (
gcc
org++
) are really important; I recommend:- general warnings and optimization flags (e.g.
-Wall
,-g
to get debug info,-O
,-flto
etc, or-c
to avoid linking , ...) - preprocessor options like
-I
include-dir and-D
defined-symbol (or-H
to understand which headers get included) etc.. - source file[s] to compile like
hello.c
orworld.cc
- if you want to link existing object files
else.o
, add them after the source files - linker options (if relevant), notably
-L
library-dir (and probably-rdynamic
if your program uses plugins with dlopen(3) ....) - libraries (like
-lfoo -lbar
from higher-level libraries likelibfoo.so
to lower-level libraries. - output file (i.e. produced executable), e.g.
-o yourexec
.
- general warnings and optimization flags (e.g.
Always correct your source code till you got no warning at all. Trust the compiler's warnings and error messages.
Learn how to use
make
and to write simpleMakefile
-s; see this example.there are other builders, e.g. http://omake.metaprl.org/ etc
- Compile your code with the
-g
flag to have the compiler produce debugging information; only when you have debugged your program, ask the compiler to optimize (e.g. with-O1
or-O2
), especially before benchmarking. - Learn how to use
gdb
- Use a version control system like
svn
orgit
(even for a homework assignment). In 2015 I recommend git oversvn
- Backup your work.
- Learn to use valgrind to hunt memory leaks.
NB
The advices above are not specific to Ubuntu 11.10, they could apply to other Linux distributions and other Ubuntu versions.
how program and compile C in eclipse IDE in ubuntu 11.10? which plug in I need to install?
You need to install eclipse CDT (C Development Kit). You can choose which compiler you want to use with CDT. You can read more here.
OpenCV on ubuntu 11.10
Why don't you use pkg-config to your favor?
g++ hello.c -o hello `pkg-config --cflags --libs opencv`
How to keep Ubuntu 11.10 and Kate editor w/terminal from changing command line when changing tabs?
From Pedro Romano at https://superuser.com/q/481362/127982:
Kate configuration under Application > Terminal > Terminal Settings
has a Automatically synchronise the terminal with the current document when possible (this is on Ubuntu 12.10, so your may not have it or be slightly different).
how can I invoke setjmp on ubuntu 11.10?
From the setjmp(3)
man page:
SYNOPSIS
#include <setjmp.h>
c math linker problems on Ubuntu 11.10
The library that you are using needs to be placed after the files that use it when you are using it from the command line. So place -lm
on after your C files on the command line.
Reference
Related Topics
Int to Unsigned Int Conversion
Why Is 'I = ++I + 1' Unspecified Behavior
Opencv 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10
How to Parse Date/Time from String
Why User-Defined Move-Constructor Disables the Implicit Copy-Constructor
C++ Boost: Undefined Reference to Boost::System::Generic_Category()
C++14 Variable Templates: What Is Their Purpose? Any Usage Example
Inherit Interfaces Which Share a Method Name
Overriding Public Virtual Functions with Private Functions in C++
What Are Primitive Types Default-Initialized to in C++
Static and Extern Global Variables in C and C++
How to Use Visual Studio 2010's C++ Compiler with Visual Studio 2008's C++ Runtime Library