欢迎大家赞助一杯啤酒🍺 我们准备了下酒菜:Formal mathematics/Isabelle/ML, Formal verification/Coq/ACL2, C++/F#/Lisp
GCC
小 (→Windows用户) |
|||
(未显示3个用户的35个中间版本) | |||
第1行: | 第1行: | ||
− | + | {{SeeWikipedia|GNU Compiler Collection}} | |
+ | [[Image:GCC-logo.png|right|GCC]] | ||
+ | |||
+ | GCC(GNU Compiler Collection) | ||
+ | |||
+ | ==简介== | ||
+ | Linux 中最重要的软件开发工具是 GCC。GCC(GNU C Compiler) 是GNU推出的功能强大、性能优越的多平台编译器,是 GNU 的代表作品之一。GCC 是可以在多种硬体平台上编译出可执行程序的超级编译器,其执行效率与一般的编译器相比平均效率要高20%~30%。 | ||
+ | |||
+ | ==新闻== | ||
+ | *[http://www.infoq.com/cn/news/2017/05/gcc-71-released GCC 7.1发布,完全支持C++17] (201705) | ||
+ | |||
+ | ==指南== | ||
+ | ===macOS=== | ||
+ | 通过[[Homebrew]]安装 | ||
+ | brew install gcc | ||
+ | |||
+ | ===Linux用户=== | ||
在 Redhat 下通过 RPM包安装 GCC | 在 Redhat 下通过 RPM包安装 GCC | ||
install gcc rpm | install gcc rpm | ||
+ | |||
+ | 获得 RPM包 http://fr2.rpmfind.net/linux/rpm2html/search.php?query=GCC&submit=Search+... | ||
rpm -Uvh gcc-3.2.3-34.i386.rpm glibc-devel-2.3.2-95.20.i386.rpm libgcc-3.2.3-34.i386.rpm cpp-3.2.3-34.i386.rpm glibc-headers-2.3.2-95.20.i386.rpm glibc-kernheaders-2.4-8.34.i386.rpm | rpm -Uvh gcc-3.2.3-34.i386.rpm glibc-devel-2.3.2-95.20.i386.rpm libgcc-3.2.3-34.i386.rpm cpp-3.2.3-34.i386.rpm glibc-headers-2.3.2-95.20.i386.rpm glibc-kernheaders-2.4-8.34.i386.rpm | ||
gcc --version | gcc --version | ||
− | |||
− | |||
http://www.linuxfromscratch.org/lfs/view/stable/chapter03/packages.html | http://www.linuxfromscratch.org/lfs/view/stable/chapter03/packages.html | ||
All Packages | All Packages | ||
− | |||
− | |||
install gcc 3.4.3 | install gcc 3.4.3 | ||
第22行: | 第36行: | ||
The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory: | The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory: | ||
− | |||
− | |||
tar -xvf *.tar | tar -xvf *.tar | ||
tar -zxvf *.tar.gz | tar -zxvf *.tar.gz | ||
− | |||
− | |||
tar -xjvf gcc-3.4.3.tar.bz2 | tar -xjvf gcc-3.4.3.tar.bz2 | ||
− | |||
− | |||
cd gcc-3.4.3 | cd gcc-3.4.3 | ||
第40行: | 第48行: | ||
cd ../gcc-build | cd ../gcc-build | ||
− | |||
− | |||
../gcc-3.4.3/configure --prefix=/tools \ | ../gcc-3.4.3/configure --prefix=/tools \ | ||
第48行: | 第54行: | ||
--disable-nls --enable-shared --enable-languages=c | --disable-nls --enable-shared --enable-languages=c | ||
− | |||
− | |||
or | or | ||
../gcc-3.4.3/configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-languages=c --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux | ../gcc-3.4.3/configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-languages=c --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux | ||
− | |||
− | |||
− | |||
− | |||
make bootstrap // make long time | make bootstrap // make long time | ||
− | |||
− | |||
make install | make install | ||
− | |||
− | |||
ln -vs gcc /tools/bin/cc | ln -vs gcc /tools/bin/cc | ||
− | |||
− | |||
[root@RHELAS3 gcc-build]# /tools/bin/cc --version | [root@RHELAS3 gcc-build]# /tools/bin/cc --version | ||
第80行: | 第74行: | ||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
− | |||
− | |||
[huihoo@RHELAS3 5]$ /tools/bin/cc helloworld.cpp -o helloworld | [huihoo@RHELAS3 5]$ /tools/bin/cc helloworld.cpp -o helloworld | ||
cc: helloworld.cpp: C++ compiler not installed on this system | cc: helloworld.cpp: C++ compiler not installed on this system | ||
− | |||
− | |||
run testsuite | run testsuite | ||
− | |||
− | |||
[huihoo@RHELAS3 testsuite]$ gcc -v | [huihoo@RHELAS3 testsuite]$ gcc -v | ||
第102行: | 第90行: | ||
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-53) | gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-53) | ||
− | |||
− | |||
libstdc++ install | libstdc++ install | ||
− | |||
− | |||
http://gcc.gnu.org/libstdc++/ | http://gcc.gnu.org/libstdc++/ | ||
http://mirrors.kernel.org/gnu/ | http://mirrors.kernel.org/gnu/ | ||
− | |||
− | |||
Porting libstdc++-v3 | Porting libstdc++-v3 | ||
http://gcc.gnu.org/onlinedocs/porting/ | http://gcc.gnu.org/onlinedocs/porting/ | ||
− | |||
− | |||
[huihoo@RHELAS3 libstdc++-v3]$ ./configure | [huihoo@RHELAS3 libstdc++-v3]$ ./configure | ||
configure: error: cannot find install-sh or install.sh in ./../.. | configure: error: cannot find install-sh or install.sh in ./../.. | ||
− | |||
− | |||
− | |||
./configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-cstdio --enable-clocale --enable-libstdcxx-allocator --enable-threads --enable-threads=posix --enable-libstdcxx-debug --enable-c99 --enable-long-long --enable-fully-dynamic-string --enable-concept-checks --enable-libstdcxx-pch --disable-hosted-libstdcxx | ./configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-cstdio --enable-clocale --enable-libstdcxx-allocator --enable-threads --enable-threads=posix --enable-libstdcxx-debug --enable-c99 --enable-long-long --enable-fully-dynamic-string --enable-concept-checks --enable-libstdcxx-pch --disable-hosted-libstdcxx | ||
− | |||
− | |||
RHEL3 | RHEL3 | ||
第142行: | 第117行: | ||
/usr/lib/libstdc++.so.6.0.3 | /usr/lib/libstdc++.so.6.0.3 | ||
− | == | + | ---- |
+ | ===MS Windows用户=== | ||
− | + | ===Hello World=== | |
+ | 包含头文件,库的编译方式 | ||
+ | g++ main.cpp -o example -I"../../include" -L"/usr/lib" ../../bin/linux-gcc/libIrrKlang.so -pthread | ||
− | cd hello | + | 首先创建hello工程目录 |
+ | mkdir hello //创建目录 | ||
+ | cd hello //进入目录 | ||
+ | 然后建立三个文件 | ||
− | + | * hello.c | |
− | + | * configure.in // autoscan创建configure.scan,然后改名为configure.in,这里省略了这个步骤 | |
+ | * Makefile.am //Makefile模板 | ||
hello.c | hello.c | ||
− | + | #include <stdio.h> | |
− | + | int | |
− | + | main(int argc,char *argv[]) | |
− | + | ||
− | + | { | |
− | + | printf("hello world\n"); | |
− | + | return 0; | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | #include <stdio.h> | + | |
− | + | ||
− | + | ||
− | + | ||
− | int | + | |
− | + | ||
− | main(int argc,char *argv[]) | + | |
− | + | ||
− | { | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
在configure.in里加入 | 在configure.in里加入 | ||
− | AC_INIT(hello.c) | + | AC_INIT(hello.c) |
− | + | AM_INIT_AUTOMAKE(hello,0.1) | |
− | AM_INIT_AUTOMAKE(hello,0.1) | + | AC_PROG_CC |
− | + | AC_OUTPUT(Makefile) | |
− | AC_PROG_CC | + | |
− | + | ||
− | AC_OUTPUT(Makefile) | + | |
− | + | ||
− | + | ||
在Makefile.am里加入 | 在Makefile.am里加入 | ||
− | UTOMAKE_OPTIONS=foreign | + | UTOMAKE_OPTIONS=foreign |
− | + | bin_PROGRAMS=hello | |
− | bin_PROGRAMS=hello | + | hello_SOURCES=hello.c |
− | + | ||
− | hello_SOURCES=hello.c | + | |
− | + | ||
− | + | ||
and touch new files: NEWS, README,AUTHORS, ChangeLog | and touch new files: NEWS, README,AUTHORS, ChangeLog | ||
− | |||
− | |||
然后执行 | 然后执行 | ||
− | $ aclocal | + | $ aclocal |
+ | $ autoconf | ||
+ | $ automake --add-missing | ||
+ | $ ./configure | ||
+ | $ make | ||
+ | $ ./hello //执行hello程序 | ||
− | + | It's OK :) | |
− | $ | + | $ make clean //清楚编译产生的中间文件和目标文件,为打包作准备 |
− | |||
− | + | # make install // 将hello安装到 /usr/local/bin | |
− | + | /usr/local/bin/hello | |
+ | $ make dist | ||
− | + | create package file: hello-0.1.tar.gz | |
+ | $ make distcheck // 生成发布软件包并对其进行测试检查,以确定发布包的正确性。 | ||
+ | 提示: hello-0.1.tar.gz is ready for distribution | ||
− | + | ===Solaris用户=== | |
+ | ===Windows用户=== | ||
+ | [[文件:MinGW-w64-long.png|right|MinGW-w64]] | ||
+ | [https://www.mingw-w64.org/ MinGW-w64] | ||
+ | 下载 [[MinGW|MinGW-w64]] 软件包 | ||
+ | ==项目== | ||
+ | *[https://github.com/gcc-mirror gcc-mirror @ github] | ||
+ | *[[GNU Flex]] | ||
+ | *[[GNU Bison]] | ||
+ | *[https://github.com/Rust-GCC GCC Rust] GCC Front-End for [[Rust]] | ||
− | + | ==文档== | |
+ | *[http://ldp.huihoo.org/HOWTO/GCC-Frontend-HOWTO.html GCC Frontend HOWTO] | ||
+ | *[http://gnu.huihoo.org/gcc/index.html GCC online documentation] | ||
− | + | ==图集== | |
+ | ==链接== | ||
+ | *http://gcc.gnu.org/onlinedocs/ | ||
+ | *http://ftp.gnu.mirrors.hoobly.com/pub/ | ||
+ | *http://gcc.gnu.org/lists.html // mail lists | ||
+ | *http://docs.huihoo.com/gnu/ | ||
+ | *[https://gcc.gnu.org/wiki/HomePage GCC Wiki] | ||
− | + | [[category:GNU]] | |
− | + | [[category:GCC]] | |
− | + | [[category:programming language]] | |
− | + | [[category:compiler]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
2022年9月6日 (二) 01:04的最后版本
您可以在Wikipedia上了解到此条目的英文信息 GCC Thanks, Wikipedia. |
GCC(GNU Compiler Collection)
目录 |
[编辑] 简介
Linux 中最重要的软件开发工具是 GCC。GCC(GNU C Compiler) 是GNU推出的功能强大、性能优越的多平台编译器,是 GNU 的代表作品之一。GCC 是可以在多种硬体平台上编译出可执行程序的超级编译器,其执行效率与一般的编译器相比平均效率要高20%~30%。
[编辑] 新闻
- GCC 7.1发布,完全支持C++17 (201705)
[编辑] 指南
[编辑] macOS
通过Homebrew安装
brew install gcc
[编辑] Linux用户
在 Redhat 下通过 RPM包安装 GCC
install gcc rpm
获得 RPM包 http://fr2.rpmfind.net/linux/rpm2html/search.php?query=GCC&submit=Search+...
rpm -Uvh gcc-3.2.3-34.i386.rpm glibc-devel-2.3.2-95.20.i386.rpm libgcc-3.2.3-34.i386.rpm cpp-3.2.3-34.i386.rpm glibc-headers-2.3.2-95.20.i386.rpm glibc-kernheaders-2.4-8.34.i386.rpm
gcc --version
http://www.linuxfromscratch.org/lfs/view/stable/chapter03/packages.html
All Packages
install gcc 3.4.3
The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory:
tar -xvf *.tar
tar -zxvf *.tar.gz
tar -xjvf gcc-3.4.3.tar.bz2
cd gcc-3.4.3
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-3.4.3/configure --prefix=/tools \
--libexecdir=/tools/lib --with-local-prefix=/tools \
--disable-nls --enable-shared --enable-languages=c
or
../gcc-3.4.3/configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-languages=c --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
make bootstrap // make long time
make install
ln -vs gcc /tools/bin/cc
[root@RHELAS3 gcc-build]# /tools/bin/cc --version
cc (GCC) 3.4.3
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[huihoo@RHELAS3 5]$ /tools/bin/cc helloworld.cpp -o helloworld
cc: helloworld.cpp: C++ compiler not installed on this system
run testsuite
[huihoo@RHELAS3 testsuite]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-53)
libstdc++ install
http://mirrors.kernel.org/gnu/
Porting libstdc++-v3
http://gcc.gnu.org/onlinedocs/porting/
[huihoo@RHELAS3 libstdc++-v3]$ ./configure
configure: error: cannot find install-sh or install.sh in ./../..
./configure --prefix=/usr/local --mandir=/usr/share/man --infodir=/usr/share/info --enable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-cstdio --enable-clocale --enable-libstdcxx-allocator --enable-threads --enable-threads=posix --enable-libstdcxx-debug --enable-c99 --enable-long-long --enable-fully-dynamic-string --enable-concept-checks --enable-libstdcxx-pch --disable-hosted-libstdcxx
RHEL3
/usr/lib/gcc/i386-redhat-linux/3.4.3/libstdc++.so
/usr/lib/gcc/i386-redhat-linux/3.4.3/libstdc++.a
/usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6.0.3
[编辑] MS Windows用户
[编辑] Hello World
包含头文件,库的编译方式
g++ main.cpp -o example -I"../../include" -L"/usr/lib" ../../bin/linux-gcc/libIrrKlang.so -pthread
首先创建hello工程目录
mkdir hello //创建目录 cd hello //进入目录
然后建立三个文件
- hello.c
- configure.in // autoscan创建configure.scan,然后改名为configure.in,这里省略了这个步骤
- Makefile.am //Makefile模板
hello.c
#include <stdio.h> int main(int argc,char *argv[]) { printf("hello world\n"); return 0; }
在configure.in里加入
AC_INIT(hello.c) AM_INIT_AUTOMAKE(hello,0.1) AC_PROG_CC AC_OUTPUT(Makefile)
在Makefile.am里加入
UTOMAKE_OPTIONS=foreign bin_PROGRAMS=hello hello_SOURCES=hello.c
and touch new files: NEWS, README,AUTHORS, ChangeLog
然后执行
$ aclocal $ autoconf $ automake --add-missing $ ./configure $ make $ ./hello //执行hello程序
It's OK :)
$ make clean //清楚编译产生的中间文件和目标文件,为打包作准备
# make install // 将hello安装到 /usr/local/bin
/usr/local/bin/hello
$ make dist
create package file: hello-0.1.tar.gz
$ make distcheck // 生成发布软件包并对其进行测试检查,以确定发布包的正确性。
提示: hello-0.1.tar.gz is ready for distribution
[编辑] Solaris用户
[编辑] Windows用户
下载 MinGW-w64 软件包
[编辑] 项目
- gcc-mirror @ github
- GNU Flex
- GNU Bison
- GCC Rust GCC Front-End for Rust