Home  >  Article  >  Operation and Maintenance  >  Recommended configuration for C/C++ programming using Geany on Linux

Recommended configuration for C/C++ programming using Geany on Linux

PHPz
PHPzOriginal
2023-07-04 19:27:072581browse

Recommended configuration for using Geany for C/C programming on Linux

  1. Introduction
    Geany is a lightweight integrated development environment (IDE), especially suitable for C and C programming. It provides a simple and easy-to-use interface, and has some commonly used functions to improve programming efficiency. This article will introduce how to configure Geany on Linux for better C/C programming.
  2. Installing Geany
    In most Linux distributions, Geany can be installed directly through the package manager. For example, on Ubuntu it can be installed with the following command:

    sudo apt-get install geany

    Once the installation is complete, you can find Geany in the Applications menu.

  3. Configuring the compiler
    In Geany, we need to configure the C/C compiler so that we can compile and run our program. By default, Geany uses GCC as the compiler, but we still need to make sure that our system has GCC installed.

For Ubuntu users, you can use the following command to install GCC:

sudo apt-get install build-essential

For other Linux distributions, please install GCC according to the specific situation.

Once GCC is installed, we need to configure GCC as the default compiler in Geany. Open Geany and click the "Build" option in the menu bar, then select "Set Build Commands". In the pop-up window, enter the following command and save:

Compile:  gcc -Wall -c "%f"
Build: gcc -Wall -o "%e" "%f"
Execute: "./%e"

In this way, when we press F9, Geany will use GCC to compile the C/C code and execute the generated executable file.

  1. Code Example
    Here is a simple C program example that will calculate and print the first n numbers of the Fibonacci sequence:

    #include <stdio.h>
    
    int main()
    {
     int n, t1 = 0, t2 = 1, nextTerm;
    
     printf("请输入要打印的斐波那契数列的项数:");
     scanf("%d", &n);
    
     printf("斐波那契数列的前 %d 个数字是:
    ", n);
    
     for (int i = 1; i <= n; i++)
     {
         printf("%d, ", t1);
         nextTerm = t1 + t2;
         t1 = t2;
         t2 = nextTerm;
     }
    
     return 0;
    }

    Will Save this code as a file named fibonacci.c and open the file in Geany. Press F9 to compile and run the code, and you will see the first n numbers of the Fibonacci sequence in the output window.

  2. Advanced Configuration
    Geany also provides some other advanced configuration options to meet more specific needs. Access the configuration interface by clicking the "Edit" option in the menu bar and then selecting "Preferences".

In the "General" tab, you can change the editor's settings such as fonts, color schemes, and display line numbers. In the "Keybindings" tab, you can customize shortcut keys to make using Geany faster and more convenient.

In addition, plug-ins can be downloaded and installed on Geany’s official website to further expand its functionality.

Summary
Through the above configuration and code examples, you have learned how to use Geany for C/C programming on Linux. Geany is a powerful and lightweight IDE. It provides a simple and easy-to-use interface and some common functions, which can greatly improve your programming efficiency. I hope this article will help you configure C/C programming using Geany on Linux!

The above is the detailed content of Recommended configuration for C/C++ programming using Geany on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn