Continuous build: C ++ compiler environment container

gcc official mirror

gcc Docker official mirror provided on Docker Hub below, by setting the enable-languages ​​c ++ configuration options, so that the image has the ability to compile gcc c ++ code.

Here Insert Picture Description

Use docker pull command to get the most current version of the 9.2.0 version

[root@host132 ~]# docker pull gcc:9.2.0
9.2.0: Pulling from library/gcc
4a56a430b2ba: Pull complete
4b5cacb629f5: Pull complete
14408c8d4f9a: Pull complete
ea67eaa7dd42: Pull complete
4d134ac3fe4b: Pull complete
dbc65b875791: Pull complete
53308bd32679: Pull complete
da5ff526afd1: Pull complete
7704e65e7dab: Pull complete
Digest: sha256:c0f4919207ad6d73dad9f98e532f1cb224159e9c7d0a257665564526ae85bf7f
Status: Downloaded newer image for gcc:9.2.0
[root@host132 ~]# docker images |grep gcc
gcc                                    9.2.0              201020b8c956        13 hours ago        1.14GB
[root@host132 ~]#

gcc version confirmed

Use g ++ -v confirm the version of the compiler g ++ constructed with a specific implementation example is shown below

[root@host132 g++]# docker run --rm -it gcc:9.2.0 g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
gcc version 9.2.0 (GCC)
[root@host132 g++]#

a

Prepare the following c ++ demo code is compiled with

[root@host132 g++]# cat demo/src/main.c
#include <iostream>
using namespace std;
int main()
{
    cout << "Hello liumiaocn" << endl;
    return 0;
}

[root@host132 g++]#

Use g ++ to build & links

c ++ compiler to compile and link is also divided into two stages, here for a simple demonstration, step directly generate executable file. Specific examples of the implementation of the command is as follows:

[root@host132 g++]# docker run --rm -v $(pwd)/demo/src/:/demo/src -it gcc:9.2.0 g++ -o /demo/src/demo /demo/src/main.c
[root@host132 g++]#

The results confirm the files to compile and link generated:

[root@host132 g++]# ls demo/src/demo
demo/src/demo
[root@host132 g++]# file demo/src/demo
demo/src/demo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, not stripped
[root@host132 g++]#

verify results

Due to the generation of an executable file, the results can be confirmed by way of the output container
[root @ host132 g ++] # docker run --rm -v $ (pwd) / demo / src /: / demo / src -it gcc: 9.2. 0 / Demo / the src / Demo
the Hello liumiaocn
[host132 the root G @ ++] #

[root@host132 g++]# ./demo/src/demo
Hello liumiaocn
[root@host132 g++]#

to sum up

This article is just a very simple example, does not have any practical significance in the project a little more complicated, more important is dependent on the management and guidance of Makefile is the practice of combining C ++ language project in continuous integration content needs to focus attention.

Reference content
https://hub.docker.com/_/gcc

Guess you like

Origin www.linuxidc.com/Linux/2019-09/160736.htm
Recommended