C ++ programming and kdevelop environment configuration in Linux

Source: Internet
Author: User

Kdevelop is one that supports multipleProgramThe integrated development environment of the design language. It runs in Linux and other UNIX-like environments.
Kdevelop itself does not contain the compiler, but calls other compilers to compile the program.
1. Open the New Software Package Manager
2. Search for kdevelop. Check kdevelop In the result and the package with the "-dev" Suffix in the kdevelop series. Of course, you can skip this check.
3. Install the following package after installing the preceding package:
Automake
Autoconf
G ++
Libtool
Cmake
After these are installed, you can basically run them, but if you want to see the output, you have to install this thing: konsole
To use kdevelop, follow these steps:
1. Create a project
2. WriteCode
3. Build-> RUN automake & friends
4. Build-> RUN configure
5. Build-> compile File
6. Build-> build project
7. Build-> Execute Program (SHIFT + F9)
Note: This problem may occur in Step 4. Build-> RUN Configure. Configure: Error: C ++ compiler cannot create executables
This is a problem in setting kdevelop environment variables.
Enable project options in kdevelop, and then confirm in configure options that C and C ++ use compiler separately, in their respective compiler command (CC) and compiler command (cxx) in GCC and G ++ respectively. after you press OK in the dialog box, IDE will ask you if you want to recreate it. Select rerun.

 

 

1. kdevelop is just an ide. To compile a C/C ++ program, install make, GCC, And the header file:

Sudo apt-Get build-dep gcc
Sudo apt-Get installBuild-essential

2. Install kdevelop

Sudo apt-Get install kdevelop3

3. After installation, You can see kdevelop in Application> programming. The following code uses kdevelop to develop a program, and you can steal it :-)

Procedure
GenerallyKdevelop programming involves the following steps. Programming is complicated and difficult to succeed at a time.
It may be repeated multiple times.

Step 1: Create a project
You can use the menu to start the corresponding Wizard program and use it to complete the initial construction of the project.
[Project] → [new project]
When creating a new project, you must specify the project file storage location, project name, and project type, and enter the programming author
. The wizard automatically generates a batch of template files based on the selected project type (for example, a text interface program or a graphic interface program, a C program or a C ++ program.

Step 2: edit the program file
Wizard programs generally create some program files, which should be edited to meet specific programming needs.
You can also execute menu operations to add new files.
[File] → [new]
After the preceding operations, a dialog box is displayed to specify the file name and file type. The combination is automatically set based on different file types.
. Note: The "add to project" check box should be checked to ensure that the new file is added to the current project.

Step 3: generate the source code structure
After editing the program file, you must use the GNU build system to generate the source code structure. When a new file (or object
After the file (or directory) name is modified and the file storage location is changed, the source code structure should be regenerated. Specifically, the generated source code structure includes Autoconf, automake, and other operations. The makefile. Am of each subdirectory is changed to makefile. In. Program packages with source code structure can be configured, compiled, connected, and installed using simple commands (Configure/make install) on any UNIX or Linux system.
You can execute menu operations to generate the source code structure:
[Build] → [run automake & conf]

Step 4: Configure to run configure
Configure is a script used to determine the details of the system, such as the compiler, library, and
Save the location and replace the corresponding part of makefile. In to form the makefile.
You can perform a menu operation to configure it:
[Build] → [run configure]

Step 5: Compile the connection
Execute the menu operation [Build] → [built project] to complete the compilation connection and form an executable file. By default, this executable file carries the source code debugging symbol.
For multi-file programs, each file must be compiled to generate the target file. After each file is compiled, the compilation connection is unified. To compile a file that is being edited separately, perform the following operations:
[Build] → [compile file]

Step 6: Run
If you wantUnder the control of kdevelop, you can run the compiled and connected programs and perform the following menu operations:
[Build] → [excecute program]
To run the program separately, install the program first, and then enter the name of the executable file in the command line (generally
Project name.Kdevelop stores executable files in/usr/local/bin.
[Build] → [install]

Compile program files
Choose project> new project from the menu to start the new project wizard, select the project type, and specify the project name and its storage location ,. Next, click Next to create the project.
The wizard automatically generates a file containing the main function. This file is a template, and the code is modified and added based on it,
You can write the required program.

Compile
After the program is written, you should save the file and generate the source code structure, configuration, and compilation according to the steps mentioned above, that is
Perform the following menu operations:
[Build] → [run automake & conf]
[Build] → [run configure]
[Build] → [compile file]
If each operation can be completed normally, the message "success" appears in the messages window. If no success prompt is displayed, the corresponding operation fails and the cause should be identified.
Generally, both the source code structure and configuration can be successfully generated.
If the compilation connection is performed for the first time, it usually fails, because few people can write a program without any syntax errors at a time. View
The message in the messages window shows where syntax errors occur. Click an error message,Kdevelop automatically positions the cursor on the statement where the error occurs.
Correct the syntax errors in the program based on the error prompt, and then try to compile again until the success prompt appears.
A common situation is that a syntax error in a program may lead to multiple error messages. Therefore, we should set the first error
Handle the error information carefully. Then, select several random entries from the subsequent error information and compile the code again to check whether there is any error message. So many times, until all the error prompts are eliminated, the compilation is successful. Do not process all error messages in sequence and try to compile them. This is less efficient.

Generate executable files
After the compilation is successful, run build> built project to generate an executable file.

debug
next, you can perform the "build"> "excecute program" test run program on the menu. This operation is performed under the control of kdevelop. Therefore, if an "endless loop" occurs, you can choose build> stop from the menu or Press ESC to stop the program.
If a logic error exists in the program, the expected results are not obtained. It is difficult to exclude logical errors. You must carefully
analyze the program to find out the cause of the error.
General logic errors can be determined based on the program running performance. Debugging tools are required for deep logical errors.
the debugging tool gnu gdb described earlier in this chapter is a good tool. You can use it to analyze the program and find the root cause of logical errors.
. By default, after [Build] → [built project] operation, you can find the executable file with Source Code debugging symbol in/debug/src/under the project directory.
after a logical error is found, modify the program and recompile the connection. Then try again. If the expected results are still not obtained, it indicates that
the program still has a logic error and should be analyzed again. This is repeated multiple times until all logical errors are eliminated.

Publish an executable file
if you only want to publish the executable file of a program, you can first adjust the compilation connection options of the project and select the optimal compilation method. In this way, you can
get a smaller and faster executable file.
you can choose Project> build configuration to modify the compilation connection options. There are three options under this menu. The default value is Debug. The generated executable file contains the source program debugging symbol. You can also select default or optimized. When optimized is selected, the connection is optimized during compilation. The generated executable file is smaller and the execution speed is faster.
when debug is selected, the executable file is saved in/debug/src/under the project directory. When optimized is selected, the executable file is saved in/Optimized/src/under the project directory. When default is selected, the executable file is saved in/src/under the project directory.
to publish an executable file, select the optimized method to compile the connection.

Publish the source program
package the project directory and all the files in it to form the source program package. After you obtain the source package and decompress it, you do not have to install kdevelop can compile and install it in the standard way,
Configure, make, make install, make clean, make uninstall, and other commands are supported. This package also contains kdevelop project files and other related information. Therefore, if you have installed kdevelop, you can directly open the project and modify it. how to use an existing source file?
there is an automake manager tag on the right side of the kdevelop main window. Click this tab to view the folder where the source file of the project is located and the files. There is a toolbar above the window with files in the column, which is used to add files. There are two ways to add files: link and copy.

4. Problems encountered:

A) when running run automake & friend, an error is returned:

 

 

This is because automake is not installed. The solution is to run the following code on the terminal:

 

 Sudo apt-Get install automake

B) An error occurs when running run automake & friend again:

 

 

This is because libtool is not installed. The solution is

 

sudo apt-Get install libtool

C) Finally, the programming is passed, but an error is prompted in the excecute program:

Konsole not found

This is because konsole is not installed, just install

sudo apt-Get install konsole

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.