C and C++ programming on Ubuntu 11.10 [closed]

2019-01-04 01:14发布

I've recently installed Ubuntu 11.10 and along with it the CodeBlocks IDE and I am aware that I have gcc and the std libraries by default.

My questions are:

  • Do you you have any tips for a new C++ programmer on Ubuntu?
  • Any libraries I should get from the start?
  • A really good IDE I'm missing? (YMMV but I prefer to work in IDE's)
  • Any programming boons or traps I should be aware of from the start?

标签: c++ c linux ubuntu
10条回答
小情绪 Triste *
2楼-- · 2019-01-04 01:42

On the first steps of programming you should not use IDE because you will better understand what happens backside :) GCC or G++ and stdlib will be sufficient. You also should read about Makefiles, SVN(CVS, GIT), Autotools or CMake to manage your projects. If you want make GUI applications you should learn GTK+ or Qt. If you want real IDE for your needs try Eclipse with C/C++ plugins. Good luck :)

查看更多
Ridiculous、
3楼-- · 2019-01-04 01:44

Some tips besides those which are already mentioned:

  1. Valgrind is your friend in finding memory leaks. You may also use valgrind --tool=callgrind and KCacheGrind to see where does your program spend time on execution.
  2. If you are going to distribute your program, you should learn autotools or cmake. The first is a classical tool, a bit bloated, the second is more modern.
  3. Geany is a nice IDE if you are looking for something lightweight. Otherwise, take a look at Code::Blocks, Eclipse/CDT and NetBeans.
  4. Since I am not sure what you meant by "std libraries", I should mention that besides standard C library, there are a lot of POSIX functions and interfaces, which are common to most *nix-systems, including Mac OS X.
查看更多
Deceive 欺骗
4楼-- · 2019-01-04 01:47

QT Creator is a good IDE, that works well also with simple Makefile based projects. Also, as a C++ programmer you should check out Dia and Dia2Code for automatic generation of stubs from UML diagrams.

查看更多
戒情不戒烟
5楼-- · 2019-01-04 01:55

Since you ask more than one question I will answer each separately.

Do you you have any tips for a new C++ programmer on Ubuntu?

  • Learn some build system such as CMake or SCons. Although understanding how make and Makefiles work is useful there is a tendency of moving away from make to more high-level tools which also provide configure-like functionality. Make is often used for command-line build, for example with CMake you can generate Makefiles and build your projects using make.

  • Use a version control system such as git or Mercurial. I also recommend keeping those your projects you care about on some external service like github at least for the purposes of backup.

  • Pay attention to compiler warnings but keep in mind that warnings only catch a fraction of possible errors. A more complete picture can be obtained using static analysis tools and dynamic analysis tools like Valgrind.

Any libraries I should get from the start?

  • You've already got the main one which is called the C++ Standard Library. Make sure that you know what it provides.
  • Boost will cover most of the remaining needs except GUI.
  • Gtkmm and Qt are two major C++ GUI frameworks.

A really good IDE I'm missing? (YMMV but I prefer to work in IDE's)

  • Eclipse - for a long time I've been thinking of it as a Java only IDE, but in fact it is an excellent IDE for almost anything (I even wrote my PhD thesis in it using TeXlipse plugin) and C/C++ support is improving all the time. Also CMake can generate Eclipse CDT project files.

  • Qt Creator - another excellent C++ IDE. It is very fast and has native CMake support

Any programming boons or traps I should be aware of from the start?

  • From my experience the most common sources of errors in C++ are pointers and resource management in case of exceptions. Make sure you understand and use the RAII idiom and smart pointers.
  • For a more complete list of traps and recommendations see the answers to this question.
查看更多
Fickle 薄情
6楼-- · 2019-01-04 01:56

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:

  1. Always compile with -Wall -Wextra and perhaps even with -Werror -pedantic-errors
  2. Order of arguments to the compiler (gcc or g++) 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 or world.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 like libfoo.so to lower-level libraries.
    • output file (i.e. produced executable), e.g. -o yourexec.
  3. Always correct your source code till you got no warning at all. Trust the compiler's warnings and error messages.

  4. Learn how to use make and to write simple Makefile-s; see this example.

    there are other builders, e.g. http://omake.metaprl.org/ etc

  5. 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.
  6. Learn how to use gdb
  7. Use a version control system like svn or git (even for a homework assignment). In 2015 I recommend git over svn
  8. Backup your work.
  9. 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.

查看更多
The star\"
7楼-- · 2019-01-04 02:00

Eclipse/CDT runs really well on Ubuntu.

查看更多
登录 后发表回答