Ubuntu 11.10 上的 C 和 C++ 编程 [英] C and C++ programming on Ubuntu 11.10

查看:30
本文介绍了Ubuntu 11.10 上的 C 和 C++ 编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近安装了 Ubuntu 11.10 和 CodeBlocks IDE,我知道我默认有 gcc 和 std 库.

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.

我的问题是:

  • 对于 Ubuntu 上的新 C++ 程序员,您有什么建议吗?
  • 我应该从一开始就获得哪些库?
  • 我缺少一个非常好的 IDE?(YMMV 但我更喜欢在 IDE 中工作)
  • 从一开始我就应该注意哪些编程方面的好处或陷阱?

推荐答案

您不需要 IDE 即可在 Ubuntu 上使用 C 或 C++ 进行编码.您可以使用一个好的编辑器(例如 emacs,您可以对其进行配置以满足您的需要.

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.).

给新手的一些提示:

  1. 总是用 -Wall -Wextra 编译,甚至可能用 -Werror -pedantic-errors
  2. 编译器的参数顺序(gccg++)非常重要;我推荐:

  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:

  • 一般警告和优化标志(例如 -Wall-g 以获取调试信息、-O-flto 等,或 -c 以避免链接,...)
  • 预处理器选项,如 -I include-dir-D defined-symbol(或 -H 以了解包含哪些标题)等.
  • 源文件[s] 编译成hello.cworld.cc
  • 如果要链接现有的目标文件 else.o,请将它们添加到源文件之后
  • 链接器选项(如果相关),特别是 -L library-dir(如果您的程序使用带有 dlopen(3) ....)
  • 库(如 -lfoo -lbar 从较高级别的库(如 libfoo.so)到较低级别的库.
  • 输出文件(即生成的可执行文件),例如-o yourexec.
  • 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.

始终更正您的源代码,直到您完全没有收到警告为止.相信编译器的警告和错误消息.

Always correct your source code till you got no warning at all. Trust the compiler's warnings and error messages.

了解如何使用 make 并编写简单的 Makefile-s;请参阅此示例.

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

还有其他构建器,例如http://omake.metaprl.org/

注意

以上建议并非针对 Ubuntu 11.10,它们可以适用于其他 Linux 发行版和其他 Ubuntu 版本.

NB

The advices above are not specific to Ubuntu 11.10, they could apply to other Linux distributions and other Ubuntu versions.

这篇关于Ubuntu 11.10 上的 C 和 C++ 编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆