Home > Article > Operation and Maintenance > Recommended configuration for C/C++ programming using Geany on Linux
Recommended configuration for using Geany for C/C programming on Linux
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.
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.
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.
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!