installing a GCC compiler onto a Docker Container - gcc

I am trying to install mono package onto a Docker container, but mono requires
git , autoconf, libtool, automake, build-essential , mono-devel, gettext packages.
the problem I am having is that libtool requires libc-dev, and libc-dev requires gcc compiler.
The docker container does not have any compiler installed, but my local machine does.
arcolombo#acolombo:~/Documents/bedgraph_dockerfile$ dpkg --list |grep compiler
ii g++ 4:4.8.2-1ubuntu6 amd64 GNU C++ compiler
ii g++-4.8 4.8.2-19ubuntu1 amd64 GNU C++ compiler
ii gcc 4:4.8.2-1ubuntu6 amd64 GNU C compiler
ii gcc-4.8 4.8.2-19ubuntu1 amd64 GNU C compiler
ii hardening-includes 2.5ubuntu2.1 all Makefile for enabling compiler flags for security hardening
ii libllvm3.5:amd64 1:3.5-4ubuntu2~trusty2 amd64 Modular compiler and toolchain technologies, runtime library
ii libmono-compilerservices-symbolwriter4.0-cil 3.2.8+dfsg-4ubuntu1.1 all Mono.CompilerServices.SymbolWriter library (for CLI 4.0)
ii libxkbcommon0:amd64 0.4.1-0ubuntu1 amd64 library interface to the XKB compiler - shared library
ii mono-mcs 3.2.8+dfsg-4ubuntu1.1 all Mono C# 2.0 / 3.0 / 4.0 / 5.0 compiler for CLI 2.0 / 4.0 / 4.5
so my question is , what is the easiest way to get a gcc compiler onto a Docker container? should I just create a volume of these compiler directories into my docker container?
The reason I think I may need it is because I am running a website, and the website executes a docker image directly.

In your Dockerfile:
FROM ubuntu
# ...
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*

As I understand it, the OP has confused the terminology, and probably meant to ask:
installing a GCC compiler onto a Docker image
My answer starts by addressing the title of the question (regarding containers), then moves on to the intent of the question (regarding images).
If you can run a BASH shell in the container, then you don't need to manipulate a Dockerfile.
Say, for example, you try the hint from the docker run hello-world example:
docker run -it ubuntu bash
Then just run these from the shell in the container...
apt-get update
apt-get install gcc
A key point is that apt-get install in a raw Docker container may not behave as expected if you don't first run apt-get update. Expect to see...
Unable to locate package gcc
The error message when trying to install g++ without apt-get update is even more confusing due to "regex" substitution.
See also: http://www.liquidweb.com/kb/how-to-list-and-attach-to-docker-containers
docker ps -a ## list all available containers
and
docker exec -ti [CONTAINER ID] bash
This live-manipulation approach can also be used to creates images as the OP probably intended. Use docker commit to save your live container as a new image.

You could also grab an official image that already has GCC and/or some/most of the tools you need already installed. The docker store has a lot of official images already setup: https://store.docker.com/search?page_size=99&q=&source=verified
I'm not sure if it's the right mono, but they have a mono image: https://store.docker.com/images/4234a761-444b-4dea-a6b3-31bda725c427?tab=description
And an official GCC image: https://store.docker.com/images/06ad851d-f666-47d3-9ef3-e90535c141ec?tab=description
There's also buildpack-deps if you're going to be building stuff yourself: https://store.docker.com/images/9e56c286-5b40-4838-89fe-fd513c9c3bd6
You can browse by category: https://store.docker.com/search?page_size=99&q=&source=verified
And also directly search docker hub for mono or whatever your needs are: https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=mono&starCount=0

Related

Ubuntu: cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH

I am using Ubuntu 20.04, and I installed Go using Homebrew.
The version of Go is go 1.19.
When I run my application with go run . or go build ., this error comes up:
# github.com/mattn/go-sqlite3
cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH
I have tried running
sudo apt install gcc
but the terminal tells me that gcc is already the newest version (4:9.3.0-1ubuntu2).
When I run gcc -v
the terminal tells me gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
And I have already run apt update and apt upgrade already, and then reinstall gcc, but it's still version 9.4.0
My question is how do I install gcc-11? Or is it not supported in Ubuntu 20.04? Or should I not use go 1.19?
Thanks
The go developers provide a simple way to manage multiple go versions at once: https://go.dev/doc/manage-install
It should not be too hard to explore if this is a Homebrew artifact, or something generic to go, or a specific version of go on your system.
You might also look at the output of go env which should list configured defaults for various dependencies. You are looking for something like CC=gcc in the output.

Installing gfortran without administrator's permission

I want to install kaldi on the server, when I run the check_dependencies.sh, it tells me that I should install gfortran, but I'm not allowed to use sudo.
I have tried to install gfortran from anaconda, but it only shows that gfortran is not available from current channels, even though I had updated my conda.
Is there any alternative way? thanks!!
You can easily install GCC in your home directory without any root or admin rights.
Just download the source (e.g. a snapshot of your choice), run the provided ./contrib/download_prerequisites and than the holy trio configure --prefix=$HOME --enable-languages=c,c++,fortran, make, make install.
I recommend running these in a different directory. In general, just follow https://gcc.gnu.org/wiki/InstallingGCC A full example of a possible sequence of commands is at the bottom of the page.
I typically use the conda-forge::compilers package for my compilation needs. It includes C, C++, and FORTRAN, and abstracts over the platform (i.e., provides equivalent compilers for osx-64, linux-64, etc.).
In this particular case, the following environment appears sufficient to compile Kaldi:
kaldi-compile.yaml
name: kaldi-compile
channels:
- conda-forge
dependencies:
- compilers # this covers C, C++, and FORTRAN
- make
- cmake
- icu
- openblas # `mkl` could be used instead
Tested this works in the Mambaforge container:
docker run --rm -it condaforge/mambaforge bash
With:
Docker Session
## create env
mamba create -yn kaldi-compile compilers make cmake icu openblas
## activate env
conda activate kaldi-compile
## basic install instructions
cd /home
git clone https://github.com/kaldi-asr/kaldi.git kaldi --origin upstream
mkdir -p kaldi/build && cd kaldi/build
## configure, build, install
cmake -DCMAKE_INSTALL_PREFIX=../dist ..
cmake --build . --target install -- -j8

How to compile a Go application using gopacket for 32bit mips

I am trying to compile a little application using the gopacket library to linux on a 32bit mips cpu. Unfortunately I am getting loads of errors like this:
/home/cdutz/go/pkg/mod/github.com/google/gopacket#v1.1.19/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
On a "normal" linux system these seem to be defined in "pcap_unix.go" while on windows the values are coming from "defs_windows_amd64.go". I do have the libpcap in a 32bit mips version on my target system, which is good as my target system doesn't have the extra space to install all the tools needed to compile anything on it. I know that libpcap doesn't exist as a 1-to-1 version on windows, so this probably explains the "defs"-files. But I would generally expect it to have the same API as the one on my linux system.
[UPDATE]
So it seems number 1 of the things that needs to be ensured is that cgo is executed. This is done by setting the environment variable:
CGO_ENABLED=1
Next we need to ensure the mips compatible versions of the libpcap are installed (the header files are identical on any architecture). In order to do this on my Ubuntu 16.4 I first needed to enable the 'mips' archirecture:
dpkg --add-architecture mips
And add the debian repo to the /etc/apt/sources.list
deb [trusted=yes] http://ftp.de.debian.org/debian buster main
As soon as that's done, I could install the mips binaries:
apt install libpcap-dev:mips libpcap0.8-dev:mips libc6-dev:mips libdbus-1-dev:mips libpcap0.8:mips
In order to cross compile, it seems I need a gccgo version that can do that. For this I installed:
apt-get install gccgo-mips-linux-gnu
Now comes something I am not sure I did right, but when running the go build with compiler=gccgo it always picked the amd64 version and using anything else but 'gccgo' as compiler argument didn't work, so I updated the symlink in /usr/bin/gccgo to point to: 'mips-linux-gnu-gccgo-8' (in the same directory).
After all of these changes, I was able to almost build everything with this command:
go build -compiler=gccgo
If I enable the additional output with the '-x' option, I can see that cgo is now doing it's thing. It's also compiling all the other modules. But on the pcap one it now fails with:
cc1: error: command line option '-c' is valid for the driver but not for C
So this is where I'm currently stuck at.
Ok, after 3 days I think I managed to get things working and I'll summ up what I did.
In the end the gccgo path was a dead end, so instead of installing gccgo-mips-linux-gnu I installed gcc-mips-linux-gnu.
Next I set the CC environment variable to point to this:
export CC=/usr/bin/mips-linux-gnu-gcc-8
That was actually what was missing.
So summing it up on my Ubuntu 16.04 system:
dpkg --add-architecture mips
echo "deb [trusted=yes] http://ftp.de.debian.org/debian buster main" > /etc/apt/sources.list
apt update
apt install -y wget git build-essential mc
apt install -y gcc-mips-linux-gnu
apt install -y libpcap-dev:mips libpcap0.8-dev:mips libc6-dev:mips libdbus-1-dev:mips libpcap0.8:mips
export CC=/usr/bin/mips-linux-gnu-gcc-8
export GOOS=linux
export GOARCH=mips
export GOMIPS=softfloat
export CGO_ENABLED=1
go build
I hope this might help others.

Installing openssh-server, g++, gdb, and gdbserver in a docker container | Visual C++ for Linux Development + Docker

I would like to install the dependencies for Visual C++ for Linux Development, namely openssh-server, g++, gdb and gdbserver in a docker container.
I run a docker container based on an Ubuntu image I have tried ubuntu:14.04, ubuntu:12.04 and ubuntu:latest. I am running the container in interactive mode and using bash to attempt to install the dependencies.
The Visual C++ for Linux page linked above suggests that the dependencies can be installed with...
sudo apt-get install openssh-server g++ gdb gdbserver
However I'm having trouble installing them. For instance when I attempt to install gdb I get an error stating that the package could not be found...
root#f6de8c642ffa:/# apt-get install gdb
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package gdb
I have also tried prefixing with sudo without luck. I get similar errors for the other packages, except for g++ which I believe installed.
I'm presuming that these tools for C++ development can be used with a docker container. I'm new to both Linux and docker though.
How do I get these tools installed in an Ubuntu docker container?
You probably need to do an apt-get update first - these packages have probably been updated (and thus their explicit package versions have changed) since the source list in your container was written (when the image was created, not when the container was instantiated).
Once you update, apt-get install ... should be able to install them.

UHD Ubuntu 12.04 ZyBo ARMv7 32bit getting libboost-all-dev

Basic info:
I need to install UHD on my ZyBo board (by Digilent and Xilinx), but cannot. I have Xillinux Ubuntu 12.04 installed on it. It has an ARMv7 architecture of 32bits.(Go to bottom for question).
The UHD software can be installed by following the instructions here:
Installation option 1:
http://code.ettus.com/redmine/ettus/projects/uhd/wiki/UHD_Linux
An alternative installation process is:
Install Git and download source code:
sudo apt-get install git
git clone git://github.com/EttusResearch/uhd.git
Install all needed dependencies (see build guide):
sudo apt-get install libboost-all-dev libusb-1.0-0-dev python-cheetah doxygen python-docutils
Build-essential is a well packaged C++ library which is another needed
sudo apt-get install build-essential
Install and run cmake:
sudo apt-get install cmake
Next, to run the cmake program:
cd uhd/host
mkdir build
cd build
cmake ../
Ensure that all tests that are related to the main, necessary dependencies are successful.
Install and setup library path:
make
make test
sudo make install
cd uhd/host/build/lib
cp libuhd.so /etc/ld.so.conf.d
sudo ldconfig
sudo reboot
(I have also tried other website instructions and work-arounds).
PROBLEM / QUESTION:
However, the issue is that this software was made for i386 and amd64 machines. The ZyBo has an ARMv7 architecture. I used one installation guide which required the dependency of package: libboost-all-dev which is not available for my architecture. Therefore I was only to install half the requirements for UHD.
Does anyone know how to build the installation so that it can run on ARMv7 architecture or how to download the package libboost-all-dev onto an ARMv7 processor?
Thanks for the help
libboost-all-dev is available for arm, but accessing it requires Linux knowledge:
1.Search “Update Manager”
2.Click “Settings” on bottom left
3.Click on “Ubuntu Software” tab on upper left.
4.check/select the box “Community-maintained free and open-source Software (Universe)”
5.click “close” on bottom right

Resources