在CentOS系统上使用GCC编译器有许多技巧,可以帮助你更高效地编写、编译和调试C或C++程序。以下是一些常用的技巧:
sudo yum install gcc gcc-c++ make sudo yum install centos-release-scl sudo yum install devtoolset-9-gcc* scl enable devtoolset-9 bash ~/.bashrc文件:nano ~/.bashrc export PATH=/usr/local/gcc/<version>/bin:$PATH source ~/.bashrc gcc -o output_file source_file.c hello.c编译成名为hello的可执行文件:gcc -o hello hello.c gcc -E source_file.c -o source_file.i gcc -S source_file.i -o source_file.s gcc -c source_file.s -o source_file.o gcc source_file.o -o output_file gcc -Wall -Wextra source_file.c -o output_file gcc -O2 source_file.c -o output_file gcc -g source_file.c -o output_file gcc -o output_file -static source_file.c sudo yum install gdb gdb ./output_file export CC=/usr/bin/gcc-7 export CXX=/usr/bin/g++-7 g++(C++编译器)、gfortran(Fortran编译器)等。gcc multitools管理多个版本的GCC。sudo yum install gcc multilib-toolset -Wall选项开启所有警告,帮助你发现潜在的问题。CC=gcc CFLAGS=-O2 -g -Wall LDFLAGS= all: hello hello: hello.c $(CC) $(CFLAGS) $(LDFLAGS) -o hello hello.c clean: rm -f hello 通过掌握这些技巧,你将能够更高效地在CentOS系统中使用GCC编译器进行软件开发。