[DOCKER] Set up an Objective-C 2.0 development environment on Linux

It's been a long time since the trend moved to Swift, and the number of people who are interested in Objective-C has decreased in recent years, but here is a summary of how to set up an Objective-C development environment on Linux.

We have confirmed the operation on Ubuntu 18.04 and 19.10 on Docker. If you extract the contents of ʻENVandRUN` in the Dockerfile, it will work on the actual machine.

If Objective-C 1.0 is fine ...

If you're happy with the old-fashioned Objective-C 1.0, you can set up an Objective-C development environment with Clang 9 relatively easily by installing a ready-made package available with apt.

Dockerfile


FROM ubuntu:19.10

RUN set -x \
  && apt update \
  && apt upgrade -y \
  && DEBIAN_FRONTEND=noninteractive apt install -y tzdata \
  && apt install -y clang-9 make gobjc-9 gnustep-devel \
  && apt autoremove -y \
  && apt clean \
  && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*

# Set alias
RUN echo 'alias clang-objc="clang-9 \$(gnustep-config --objc-flags) \$(gnustep-config --objc-libs) -lgnustep-base -I/usr/lib/gcc/x86_64-linux-gnu/9/include"' > ~/.bashrc

CMD ["/bin/bash"]

The essence is

$ apt install -y clang-9 make gobjc-9 gnustep-devel

is. Also, in ~ / .bashrc

alias clang-objc="clang-9 \$(gnustep-config --objc-flags) \$(gnustep-config --objc-libs) -lgnustep-base -I/usr/lib/gcc/x86_64-linux-gnu/9/include"

It is defined as. This will allow you to do this within this Docker container

$ clang-objc -o hoge hoge.m
$ ./hoge

You can easily compile and execute the Objective-C source hoge.m by doing so.

If you want to use the full functionality of Objective-C 2.0 ...

If you want to take full advantage of Modern Objective-C features like, you have to set up libobjc2 in GNUstep. It cannot be installed with apt, so you need to build it from source. This is quite difficult. plaurent's GitHub repository was very helpful. The build procedure can be summarized in a Dockerfile as follows.

Dockerfile


FROM ubuntu:19.10

ENV CC clang-9
ENV CXX clang++-9
ENV CXXFLAGS -std=c++11
ENV RUNTIME_VERSION gnustep-2.0
ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig
ENV LD /usr/bin/ld.gold
ENV LDFLAGS "-fuse-ld=/usr/bin/ld.gold -L/usr/local/lib"

WORKDIR /GNUstep-build

RUN set -x \
  && apt update \
  && apt upgrade -y \
  && apt install -y git sudo clang-9 clang++-9 build-essential wget \
    subversion cmake libffi-dev libxml2-dev \
    libgnutls28-dev libicu-dev libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev autoconf libtool \
    libjpeg-dev libtiff-dev libffi-dev libcairo-dev libx11-dev libxt-dev libxft-dev \
  && apt autoremove -y \
  && apt clean \
  && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*

# Build GNUstep make
RUN set -x \
    #
    # Checkout tools-make
    && git clone https://github.com/gnustep/tools-make.git \
    #
    # Build GNUstep make
    && cd tools-make \
    && CC=${CC} ./configure \
            --with-layout=gnustep \
            --disable-importing-config-file \
            --enable-native-objc-exceptions \
            --enable-objc-arc \
            --enable-install-ld-so-conf \
            --with-library-combo=ng-gnu-gnu \
    && make -j8 \
    && sudo -E make install \
    && . /usr/GNUstep/System/Library/Makefiles/GNUstep.sh \
    && echo ". /usr/GNUstep/System/Library/Makefiles/GNUstep.sh" >> ~/.bashrc \
    && echo "export RUNTIME_VERSION=gnustep-2.0" >> ~/.bashrc \
    && echo 'export CXXFLAGS="-std=c++11"' >> ~/.bashrc \
    && cd .. \
#
# Build libdispatch
    #
    # Checkout swift-corelibs-libdispatch
    && git clone https://github.com/apple/swift-corelibs-libdispatch \
    && cd swift-corelibs-libdispatch \
    && git checkout swift-5.1.1-RELEASE \
    #
    # Build libdispatch
    && rm -Rf build \
    && mkdir build \
    && cd build \
    && cmake .. \
         -DCMAKE_C_COMPILER=${CC} \
         -DCMAKE_CXX_COMPILER=${CXX} \
         -DCMAKE_BUILD_TYPE=Release \
         -DUSE_GOLD_LINKER=YES \
    && make \
    && sudo -E make install \
    && sudo ldconfig \
    && cd ../.. \
#
# Build libobjc2
    #
    # Checkout libobjc2
    && git clone https://github.com/gnustep/libobjc2.git \
    && cd libobjc2 \
    && git submodule init \
    && git submodule sync \
    && git submodule update \
    #
    # Build libobjc2
    && rm -Rf build \
    && mkdir build \
    && cd build \
    && cmake .. \
         -DCMAKE_C_COMPILER=${CC} \
         -DCMAKE_CXX_COMPILER=${CXX} \
         -DCMAKE_ASM_COMPILER=${CC} \
         -DTESTS=OFF \
    && cmake --build . \
    && sudo -E make install \
    && sudo ldconfig \
    && cd ../.. \
#
# Build GNUstep make second time
    && cd tools-make \
    && CC=${CC} ./configure \
            --with-layout=gnustep \
            --disable-importing-config-file \
            --enable-native-objc-exceptions \
            --enable-objc-arc \
            --enable-install-ld-so-conf \
            --with-library-combo=ng-gnu-gnu \
    && make -j8 \
    && sudo -E make install \
    && . /usr/GNUstep/System/Library/Makefiles/GNUstep.sh \
    && cd .. \
#
# Build GNUstep base
    #
    # Checkout libs-base
    && git clone https://github.com/gnustep/libs-base.git \
    #
    # Build GNUstep base
    && cd libs-base \
    && ./configure \
    && make -j8 \
    && sudo -E make install \
    && cd .. 

# For GUI programming
#
# Build GNUstep GUI Library
RUN set -x \
    && . /usr/GNUstep/System/Library/Makefiles/GNUstep.sh \
    #
    # Checkout libs-gui
    && git clone https://github.com/gnustep/libs-gui.git \
    #
    # Build GNUstep GUI Library
    && cd libs-gui \
    && ./configure \
    && make -j8 \
    && sudo -E make install \
    && cd .. \
#
# Build GNUstep GUI Backend
    #
    # Checkout libs-back
    && git clone https://github.com/gnustep/libs-back.git \
    #
    # Build GNUstep GUI Backend
    && cd libs-back \
    && ./configure \
    && make -j8 \
    && sudo -E make install \
    && cd ..

WORKDIR /workdir

# Clean build directory
RUN rm -rf /GNUstep-build

# Set alias
RUN echo 'alias clang-objc="\${CC} \$(gnustep-config --objc-flags) \$(gnustep-config --objc-libs) -fobjc-arc -lobjc -ldispatch -lgnustep-base"' >> ~/.bashrc

CMD ["/bin/bash"]

It was a long build procedure ... Finally to ~ / .bashrc

alias clang-objc="\${CC} \$(gnustep-config --objc-flags) \$(gnustep-config --objc-libs) -fobjc-arc -lobjc -ldispatch -lgnustep-base"

Is set, so in this Docker container

$ clang-objc -o hoge hoge.m
$ ./hoge

You can easily compile and run the Objective-C 2.0 source hoge.m by doing so.

Dockerfile and set of test files

The Dockerfile created this time and the set of Objective-C sources for testing have been uploaded to the GitHub repository.

$ docker run --rm -it -v $(pwd):/workdir doratex/clang9-objc2:latest /bin/bash
# cd test
# ./test_all.sh

You can test various Objective-C 2.0 features with. (However, the last GUI test of the tests will not work unless it is connected to the X Window System server.)

Docker image

The Docker image created this time is uploaded to Docker Hub repository.

$ docker pull doratex/clang9-objc2:ubuntu1910

You can use it if you do.

Recommended Posts

Set up an Objective-C 2.0 development environment on Linux
Set up a Python development environment on Marvericks
Set up Python environment on CentOS
Build an LNPP environment on Amazon Linux 2
Set up golang with goenv on GNU / Linux
Set up python Tornado environment on raspbian jessie
Build an Arch Linux environment on Raspberry Pi
Set up TinyGo development environment for VS Code
Set up a development environment for natural language processing
Set up Docker on Oracle Linux (7.x) with Vagrant
Create an environment for MkDocs on Amazon Linux (attempted)
[Part 1] Let's set up a Minecraft server on Linux
Cross development environment (developing programs for windows on linux)
Set up a Python development environment with Sublime Text 2
Set up Python 3.4 on Ubuntu
Django environment development on Windows 10
Linux environment construction (on WSL environment)
Set up a Python development environment with Visual Studio Code
Build an Ubuntu python development environment on Google Cloud Platform
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
I want to set up a GUI development environment with Python or Golang on Mac
Setting up OpenSSH on Arch Linux
Prepare Python development environment on Ubuntu
Create a Linux environment on Windows 10
Python development environment construction on macOS
[Linux] Docker environment construction on Redhat
Install Python development environment on Windows 10
Introduce Python 3.5.2 environment on Amazon Linux
Run cron on Amazon Linux (set on Linux)
I tried to create an environment of MkDocs on Amazon Linux
Create an AWS Cloud9 development environment on your Amazon EC2 instance
How to set up the development environment of ev3dev [Windows version]
Addition of local development environment on MacOS
I created an SFTP-only user on Linux.
Set the environment variable PYTHONPATH on zsh
Build an NFS server on Arch Linux
Set up Pipenv in Pycharm in Windows environment
Create an OpenCV3 + python3 environment on OSX
On Ubuntu Linux, set Tab to q
Install rJava on Linux in R3.6 environment.
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows
Introduce VS Code and Remote Development to an offline environment to make linux development comfortable
Building an environment for matplotlib + cartopy on Mac
Build a Python development environment on your Mac
Set a fixed IP in the Linux environment
Build a Kubernetes environment for development on Ubuntu
How to build Java environment on Ubuntu (Linux)
Build a mruby development environment for ESP32 (Linux)
Create a Python virtual development environment on Windows
Build a Python development environment on Raspberry Pi
Set the startup script on Linux (RasPi, Edison)
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build an OpenCV4 environment on Raspberry Pi using Poetry
Build a Django development environment using pyenv-virtualenv on Mac
Set up a simple local server on your Mac
Build a local development environment for Laravel6.X on Mac
Set up a file server on Ubuntu 20.04 using Samba
Building an environment for "Tello_Video" on Mac OS X
Notes on creating a python development environment on macOS Catalina
Create a comfortable Python 3 (Anaconda) development environment on windows