C + + development tools under Linux

Source: Internet
Author: User
Tags gcov thread stop valgrind perl script automake

In the case of C + + development tools, compared to Windows under Microsoft (VC, VS2005, etc.) eminence, Linux/unix C + + development, is a variety of various. Emacs, VI, Eclipse, anjuta,kdevelop and so on.
Under Windows, development tools are presented to end-users in the form of an integrated development environment IDE. For example, VS2005 integrates editor, macro Assembler ml,c/c++ compiler cl, resource Compiler RC, debugger, document Generation tool, NMAKE. They are provided to end users in an integrated manner and are very convenient for beginners. However, this business model directly leads to poor user customization, is not conducive to automation, and the ability to integrate third-party tools is weak. For example, you cannot customize some macros to handle repetitive operations, and you do not realize the makefile one step pleasure of automation; You cannot remotely log on to the server for development, and you cannot use some kind of "binder" to effectively invoke third-party tools (for example, text Tools, string tools). It can be said that good business support and fool-type development are their main advantages.
Under Linux, development tools are cut into separate gadgets. Each deal with a different problem. For example, the editor (Emacs, VIM) is used for editing programs, the debugger (GDB) is used to debug programs, the compiler (GCC) is used to compile and link programs, the Performance analysis tool (Gcov, gprof) is used to optimize the program, the document generator (Doxygen) is used to generate documents. At the same time, there are some system tools and system knowledge, we are very necessary to understand: Program Automation mechanism makefile, System binder shell, System Finder Tool grep, locate, find. Other tools (such as Ctags, OCI's MPC, etc.), once mastered, will be the weapon in your hands.
This article is mainly about some of the experience of using Linux development tools. Because of the variety of tools, we do not have the ability or need to introduce each. For Linux under IDE tools, such as Eclipse, Anjuta, and so on, although they are also very useful, but it is relatively simple to use, and currently is not mainstream. Therefore, they will not be highlighted. At the same time, this article does not intend to write the operating manual of each tool, only focus on the various tools to solve the problem, operating mechanism and main characteristics.
Body
Editor
To develop, the first thing to do is to choose an appropriate editor. There are several features of the editor selection:
1) Reduce the editing time by reducing unnecessary editing actions.
All the editing tasks that can be described without ambiguity could and should be automated. For example, every C + + program will have a main function, and when we define the. h file, we want to include some preprocessing directive # define to help us solve the problem of repeatedly referencing the same header file. Mouse operation is always slower than keyboard operation. This aspect of Emacs can be considered to be the ultimate. So, Emacs users often boast that they are editing at the same speed as they think.
2) High scalability.
Programmers expected editors should be able to provide some programmatic help, such as syntax highlighting, auto-completion, automatic typesetting, grammar checking, and so on. Take a look at Gedit, Vim, Emacs, and UltraEdit, and you'll find that they're far more primitive than Windows Notepad, WordPad provides. For a new language, the new syntax, they should be able to easily provide support, rather than stay in one or several fixed language.
3) High user-customizable nature.
If you want to work long-term research and development, especially under the Linux/unix, then you need to learn a functional enough editor. There is a sentence: Linux programmers are divided into three kinds, using Emacs, using VI, and others.
Emacs is a GPL editor written by Stallman in the Lisp language. The Emacs we're talking about here refers to GNU Emacs, not xemacs. Because of its openness, we can make it a powerful IDE. After we have installed the Cgywin, we can also use EMACS under the Windows system. Cgywin and MinGW are third-party tools that simulate POSIX systems on Windows systems.
Emacs is more of an operating system than an editor. We can use it to write programming, to write wikis, to send and receive emails, and so on. Emacs is mainly extended in two ways: El script (Elisp is a dialect of Lisp) and third-party expansion packs. Emacs's entry costs are high. Because it is a purely keyboard operation, you need to remember a large number of shortcut keys, powerful is through the user to add some extension packages, Lisp script to achieve. How to properly configure and modify is very patient and skillful.
Compiler
The compiler prefers GCC (GNU COMPILER COLLECTION). There are two reasons for this, which is GNU open source, and it supports up to 96.15% of standard C + +. And vc++6.0 's support is only 83.43%. GCC is not only the usual C or C + + compiler, it can also compile other languages such as Java. GCC is the GNU C compiler, g++ is the GNU C + + compiler, and Egcs (enhanced GNU Compiler Suite) can be considered an improved version of GCC.
The compiler language from the source program to the target code will go through the following stages: the source program-> Assembler-> compiled into an obj program, linked to the final executable program. We can do all the steps with a compile instruction. You can also step into the execution. GCC has three important options-E (preprocessing only),-s (generate assembly code),-g (Generate executable with the original code debug symbols, if you want to debug with GDB, you should open this option at compile time).
GCC can be seen as a package, in addition to the compiler tool, it also integrates debugger GDB, profiling Tools Gcov, Gprof. As long as we have GCC installed, these powerful tools can be used directly.
With Gcov, we can view a program that runs each line of code in the source code. When we optimize the code that runs the most, we can greatly optimize the program. When using Gcov, you need to open GCC's Fprofile-arcs and ftest-coverage two options. The options commonly used in Gcov are the-B branch statistics.
With the Gprof tool, we can see the order of calls between functions and the time each function runs. We can understand gprof as a linux/unix with the tool time. When using gprof, you need to turn on the PG option for GCC.
The common denominator of Gcov and gprof is that when compiling a program, it is necessary to add some of its own auxiliary information, which can be diagnosed by the program. In addition to these optimizations, we can also use some memory leak tools to reduce the amount of memory space that is not released by the wild Pointer.
Debugger
GDB is the GNU debugger, which is a performance-quality debugger that comes with GCC. By combining GDB and scripting, we can implement regression testing well.
GDB can run on both CLI and GUI two modes. The default gdb is CLI mode, we can go to download and install GUI mode gdb, such as XXGDB, DDD, etc. A better way is to use GDB in Emacs. GDB includes all the debugging features of the Visual Studio Tools, and includes features that it does not have. In addition to support, we generally set breakpoints, single-step tracking, step in, step out, step over, and some other powerful features. In gdb, we can pause in the following ways: Breakpoints (breakpoint), Observation points (watchpoint), Snap points (catchpoint), signal (signals), thread stop (threads Stops).
Here are a few of the features that impressed me. 1) The Watch command allows the program to pause when the value of a variable is changed. 2) with the print instruction, set the value of the variable when the program runs, and run a method supported by the program itself. 3) with the until instruction, we can let the program pause when it runs to a program. 4) Pass the break: if directive, which causes the program to pause when it satisfies a bool expression.
Adhesive
I want to use the word "adhesive" to express the "glue" that binds multiple tools together. For example, through shell scripting, we can concatenate OS commands, sed instructions, awk commands, and other script files to play their combined forces. In Linux C + + programming, we will inevitably use the makefile file. Through, it can be compiled instructions, generate document operations, cleanup operations and so on series together. In a sense, it is also equivalent to an adhesive.
The starting point of makefile is to maintain the dependencies of many files in a project, thus obtaining a topology diagram of the source program. When we modify only one of the nodes in the diagram, we just need to compile the associated link in the topology diagram. As a result, the compilation time is greatly shortened. Make has two major concepts: dependencies and rules. Rules rule defines an action rule for each dependency dependency. This fine-grained separation allows us to customize the behavior of software builds. For example, modify the compiler used, modify the Includepath, modify the LIBPATH, modify the compilation options, and so on. NMAKE in our common VC, features and make are similar.
The focus and difficulty with make is to write makefile files. Makefile's syntax is quite different from other languages, so we should pay special attention to the difference between tab and SPACEBAR. There are many tools available to help us generate makefile. The most famous is the GNU autoconf. The preparation of a GNU program requires AutoScan, aclocal, autoconf, automake four tools.
We know that the three steps of the GNU Software Installation are:./configure, make, make install. One of the./configure is to generate a makefile file based on autoconf, alocal and other tools. The make command calls the make command to compile the source program according to the rules of the makefile file. The make install is the action (typically a copy operation) indicated by the install rule in makefile. Make Clean is the action (typically an RM operation) that is indicated by the clean rule in makefile. When we developed managed C + + project with ECLISPE+CDT, it generated makefile by objects.mk,subdir.mk,sources.mk three files. We look at the output information at compile time, and we can see the contents of the makefile file displayed.
It can be said that if you want to compile a cross-platform C + + program, then makefile is the most convenient mechanism.
OCI has written a great Perl script--MPC for the Ace,tao Open source community in Douglas C.schmidt. It consists of platform information, a rule file, source code, generate the project files that the user wants, such as make, Nmake, Visual C + + 6, Visual C + + 7, and so on. Google Web Tookit, Celtix do things similar, but they are for Java, and the MPC is for C + +.
Conclusion
Domestic data too much of the low-level duplication, often a Web page was repeatedly reproduced, and answer questions when the depth is not enough. The order of personal information is: Check the quick start or how to document-> Help (if it seems not too difficult)-> Baidu check the Chinese web page, to clarify the basic concept->google check-> A few big, related Web site Check the information-> See the Help. In addition, face in-person communication is very important, we can talk about the concept of each other, exchange a bit of experience. Unfortunately, this atmosphere around me is still not enough.
The development of Linux can also be more friendly. Personal feeling, Linux development in the domestic common programmers in large-scale popularization, there is a long way to go. The main reason why Ubuntu is hot is that it helps users set some default configurations. Users who want to add new services, they provide a good, effective support. So, I think we can take a tradeoff between the two states of the IDE and now a widget of Linux. That is, for several major needs of users, release some of the configured environment. In particular, Emacs's various El scripts (such as the interface theme of the Color-theme, C + + language editing strategies, code style settings scripts, various Emacs system settings), third-party expansion packages (template templates, programming support package Cedet, etc.). It makes no sense for every user to waste time making these configurations! Tools are always tools, we can't be slaves to tools, we can't waste a lot of our energy on configuration tools.
It is noteworthy that the current emerging eclipse has a tendency towards this. But now that Emacs is doing well, ecilpse can go beyond it, we still have to be seen. We can do C + + development by installing the SDT plugin on eclipse. However, it does not currently support debug functionality, and is not stable enough to function well. For example, sometimes you die for no reason, and if you want to turn to a functional prototype through eclipse, then it will be a long, anxious wait for you to be greeted.
Because I lack the development experience of the actual large-scale program under Linux, the understanding of many tools and mechanisms is relatively superficial. The familiarity with them is really practical, and there is a long way to go.
I was a C programmer, and is a Windows programmer, in Windows using vc6.0/vs2005 and other Microsoft's Fool tool work, for that VC 6.0/vs2005 Quick operation, debug operation is so familiar, can say VC 6.0/vs2005 is the best tool to develop C + + in Windows, you can see the call stack, memory changes, variable values, and also install visual Assist X after the VC seems to be so perfect.
However, the code under the Windows to Linux is problematic, so it is recommended in the VC tool-"Options-" tab-Tab size 4, insert a space, the other problem is that carriage return to line the problem, such as Windows is 0d,0a, To Linux under the VI see are ^m, to others inconvenience, so if the submission of the server is Linux, and you are developed under Windows, you can set in Svn/cvs, you can automatically dos2unix conversion, related documents can be viewed svn/ CVS related manuals, all of which have such settings.
Fortunately this time I transferred to the development of Linux, fortunately to know the Linux, but the attendant is a special headache problem: Linux under what tools to encode, compile, debug it?? I feel very confused, and then is the Internet big search, see so many netizens recommended vim, I was disappointed, special disappointment, and then with Vim knocked an afternoon, tired hand of hemp, feel special uncomfortable, like with the left hand to take chopsticks, the whole body of power can not cast, so I still plan to look for see. But then I found a tool that was right for me. Oh, it is so happy, today I myself these days collected some of the information collated, for the future to the Linux programmer a little hint!
The main tools are as follows:
1. Vim + ctags + taglist + cscope + cppcomplete + Global
This I have also tried, the more useful posts are as follows:
http://www.linuxsir.org/bbs/showthread.php?t=241578
Http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx
But this has a lot of commands to remember, but fortunately, these commands can be remembered in two or three days.
I have a simple booklet here:
2, the operation of the text
~
: e! File1 editing a new file under the current file
: r/etc/passwd realization of File read-in function
: Wq Hold and exit
: q! Forced exit
O: Re-start a row
U: Undo: C-r: Redo
DD Deletes a row d$ after deleting the line
E: Mobile word ge?-––àe
%: Parentheses match
33G: Jump To line 33
GG: Jump to the first line
C-o/c-i round-trip jump
H–home L–last
MA: Define label A, ' A: back to a
C-V Text block operations
/\
YY: Copy one line, p: Paste
^ Quickly jump the cursor to the first line character of the bank
$ quickly jumps the cursor to the line end character of the bank
: M,ny copy text from line m to nth line to VI buffer

5.3. Replace operation
: S/old/new replaces the first character of the current line with the character new
: S/old/new/g replaces all characters of the current line old as character new
: M,ns/old/new/g replaces all characters of the current line number m to line number n old as character new
:%s/old/new/g replaces all characters of entire text old as character new

5.7, using the replacement of the confirmation function
: S/old/new/c replaces the first character of the current line with the character new and prompts the user to confirm the action
: S/OLD/NEW/GC replaces all characters of the current line with the character new and prompts the user to confirm the action
: M,NS/OLD/NEW/GC replaces all characters of the current line number m to line number n old to character new and prompts the user to confirm the action
:%S/OLD/NEW/GC replaces all characters of the entire text old as character new and prompts the user to confirm the action
: Edit foo.txt-Editing another document
: Next for file switching
c-w Switch window
Vimdiff main.c~ MAIN.C
: g+//+s/foobar/barfoo/g
CTags:
Ctags–r/ctags *
: Set tags =/. /tags
: Tlist
F3 Find
: Make
: CW:CN:CP
MM label, F2 switch
Cscope–rbq
: CS Add/.. /cscope.out/.. /
: CS Find g xxx
: CS Find C Vim_strsave
: CW
Press the TAB key to complete the auto-completion.
The disadvantage is: auto-complete function trouble, must first establish ctags, write code or very tired, I wrote an afternoon, written hands are numb. Error checking ah, brackets automatically match ah,
Word complement function Ah, are not satisfied with, in addition to C + + support is not good.
Like I just wrote 2 config.h,config.cpp, these 2 files.
No ctag,cscope operation, you can not complete the word, bracket matching can not be detected, I do not know whether the configuration has a problem or what happened ah.
Also cannot debug, so I can only give up.
2.emacs+ Plug-in
can view
http://blog.163.com/yu_hongchang/blog/static/3989413820081121512613/
This I did not test, estimate and vim like, are command operation, heard that this function is powerful, can be debugged through xterm, this I used before, but that xterm really not good, interface, mouse, I do not like.
3. KDevelop
This tool is bad, I do not like it, such as his auto-completion function is very uncomfortable, such as: there is a function
int test (int c1,int C2)
When we knock TEs, can only appear test, and the following parameter list can not be displayed, so when the code is relatively large, function parameters are more, we can not remember parameters, no parameter list hint, will feel very uncomfortable. But fortunately, it integrates the KGDB can be debug.
4.eclipse +CDT
A lot of people with this IDE, still good, but Eclipse is a Java, running slowly, the other word complement function is too bad, can only complement the whole structure or class, write down./-can be completed, in addition to press control+/to complete, It is not possible to automatically display the code at the same time, and Eclipse's support for C/s + + is far less powerful than Java, but at least I think it is more comfortable than writing in vim, and it may be that a person is accustomed to the IDE's working environment.
5.code::blocks
can view:
http://www.codeblocks.org/
Support platform is not complete, my is Redhat Enterprise Edition 5.0, on the installation is not up, so I also did not have a glimpse of its hosting, unfortunately AH.
6. Anjuta
This I downloaded the installation is not up, do not know why, but also requires more configuration, also more trouble, if you are interested, you can see
Http://hi.baidu.com/my2008space/blog/item/140de5255fab81084c088d1e.html
7. Kylix
This has not been tried.
8.netbeans
This is also good, I have tried to meet my function, but can be customized a little close, but can meet the need, but also good, if not to mention the following slick edit, I will choose it.
9.windows Ue+ssh
There are a lot of people use this method, I do not like, probably do not like UE that interface bar, should be similar to vim and so on.
10.slick Edit
Oh, I finally chose this, very easy to use, can be customized strong, support the language is many, very easy to debug, and fast, the interface and VC 6.0 very similar, is a unique and VC comparable to the tool, but not free, but still want to thank those hackers, Let this software be cracked,
You can download it via the following link:
http://www.slickedit.com/content/view/409/239/
Download SlickEdit v14.0.2.2
And then to http://download.csdn.net/source/1481066.
Go to download the cracked file and then overwrite on it.
This tool is very useful ah, you can try Ah,
The best part of this tool is the ability to view memory, which I like. Oh
11. Compilation Tools and Debug Tools
The main compiler tools are GCC, when the code is a large amount of time to write makefile, the other debugging tools are mainly GDB, these visual Ides are basically packaged gcc, gdb. So slickedit for me this just turned to Linux, Makefile is not familiar with the person is undoubtedly a life-saving straw, can let me quickly into the work state, of course, you just think of it as a tool for editing, you will also find that it can greatly reduce your coding time, Make your hands feel tired of writing code.
Finally the dust settles, I will use SlickEdit to start my Linux tour.
1. C + + compiler gcc/g++
For more information, please refer to the website: http://gcc.gnu.org/
2. UML Modeling Tools BOUML
Linux is a more useful modeling tool, equivalent to the rational rose under windows, has become a program UML model design, code editing, code generation function and other functions.
For more information, please refer to the website: http://bouml.free.fr/
3. Makefile File Authoring tool: Autoconf,automake
Make is a very important compilation command, both in Linux and in the UNIX environment. Whether you're doing project development yourself or installing applications,
We often use make or do install. With make tools, we can break down large-scale development projects into more manageable modules.
For an application that includes hundreds of source files, it is a challenge for any programmer to manually write makefile by looking up the help documentation for make.
Fortunately, the GNU-provided autoconf and Automake are two sets of tools that make writing makefile no longer a challenge.
Using make and makefile tools, you can easily straighten out the various source files between the complex interrelationship, autoconf,automake generally with libtool use.
Please refer to the website for details:
http://www.ibm.com/developerworks/cn/linux/l-makefile/
http://www.gnu.org/software/autoconf/
http://www.gnu.org/software/automake/
http://www.gnu.org/software/libtool/
4. Debugging Tools: GDB
Programming under window, debugging tools have become to the VS environment, debugging under the Linux/unix through GDB debugging, personally think that GDB debugging more efficient than vs debugging.
For more information, please refer to the website: http://www.gnu.org/software/gdb/
5. Memory Leak tool: Valgrind
For moving thousands of lines of code, it is difficult to manually ensure that the memory is not leaking,
Valgrind detects memory leaks and out-of-bounds bugs by using memory requests and releasing matching rules. Of course, good programming habits are also essential to ensure code quality is high.
Reference website: http://valgrind.org/
6. Source Code Control Tool: SVN
Software development is no longer a personal master of the era, are in a team way to develop, how to ensure the synchronization of code, collaborative development, SVN gave us a very good help.
For more information, please refer to the website: http://svncorp.org/
7. Network Protocol analysis tool: Wireshark
To write a network program, it is inevitable to deal with network protocols and analyze network data. Wireshark provides a variety of information about the network layer and upper layer protocols.
Tcpdump can be used to analyze network protocols under command line.

C + + development tools under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.