[RUBY] How to install c2ffi on Ubuntu, which automatically parses C header files

What is c2ffi

If you're writing a C binding, you might want to have a tool that automatically parses C and C ++ header files. c2ffi is a tool that uses LLVM, and is a convenient tool that analyzes C and C ++ header files and creates a json file of metadata.

This article records the steps taken to use c2ffi on Ubuntu.

Get the source code

git clone https://github.com/rpav/c2ffi

Switch branches according to the LLVM version. Here, the LLVM of the package distributed by Ubuntu is version 10, so switch to 10.

sudo apt install llvm-10-dev libclang-cpp10-dev
git branch -a #View branch list
git checkout -b llvm-10.0.0 refs/remotes/origin/llvm-10.0.0

Install the latest version of cmake

Now, as the official README says, when I create a build directory and run cmake .., it says cmake is out of date.

mkdir build
cd build
cmake ..

An error occurs

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.17 or higher is required.  You are running version 3.16.3


-- Configuring incomplete, errors occurred!

Therefore, there is no choice but to install the latest version of cmake.

cd ../../ #Outside the c2ffi directory
git clone https://github.com/Kitware/CMake
cd CMake
git checkout -b v3.19.2 refs/tags/v3.19.2 #Latest release version
./bootstrap && make # -j8

Wait a few minutes. CMake is probably used in a variety of tools, so there's a good chance you'll get into trouble later. Do checkinstall instead of make install so that you can easily uninstall it later.

sudo checkinstall

Modify the options as appropriate and install. Since cmake is large, this process also takes some time. Once you're done, restart the shell and you'll be able to use cmake. Check if cmake can be used.

#Rebooting the shell
cmake --version
# cmake version 3.19.2

The latest version of CMake has been installed. You will be returned to the c2ffi directory.

cd ../c2ffi

Environment variables need to be set when making

I wonder if it will work this time

cd build
cmake ..
make # -j8

I get the error message / usr/bin/ld: -lclang-cpp not found. This does not disappear even if you do sudo apt install libclang-cpp10-dev etc. Refer to the following issue

LIBRARY_PATH=/usr/lib/llvm-10/lib/ make

will do. I went to the end with this. After reading the article in this issue, it seems that you may need another environment variable on your Mac as well. checkinstall. I think that Summary and Name will not be specified correctly if it is left as it is, so rewrite it to c2ffi.

sudo checkinstall

This will end soon. Type c2ffi to see if you can use c2ffi correctly.

c2ffi: unrecognized option '--version'
Usage: c2ffi [options ...] FILE

Options:
      -I, --include        Add a "LOCAL" include path
      -i, --sys-include    Add a <system> include path
      -D, --driver         Specify an output driver (default: json)

      -o, --output         Specify an output file (default: stdout)
      -M, --macro-file     Specify a file for macro definition output
      --with-macro-defs    Also include #defines for macro definitions

      -N, --namespace      Specify target namespace/package/etc

      -A, --arch           Specify the target triple for LLVM
                           (default: x86_64-pc-linux-gnu)
      -x, --lang           Specify language (c, c++, objc, objc++)
      --std                Specify the standard (c99, c++0x, c++11, ...)

      -E                   Preprocessed output only, a la clang -E

I think it's OK if it is displayed like this.

After that, let's use c2ffi to accompany the binding creation.

Officially, we provide common-lisp and a bindig generation tool for Ruby, but Ruby is older so I'm not sure if it still works.

That's all for this article.

Recommended Posts

How to install c2ffi on Ubuntu, which automatically parses C header files
How to install WildFly on Ubuntu 18.04
How to install production Metabase on Ubuntu
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
How to install multiple JDKs on Ubuntu 18.04 LTS
How to install NVIDIA driver on Ubuntu ssh destination
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
How to install java9 on elementaryOS Freya or Ubuntu 14.04 LTS
How to install ImageMagick on Windows 10
How to use Bio-Formats on Ubuntu 20.04
How to install MariaDB 10.4 on CentOS 8
How to build vim on Ubuntu 20.04
How to install and use Composer on an ECS instance on Ubuntu 16.04
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to install Adopt OpenJDK on Debian, Ubuntu with apt (-get)
How to install Eclipse (Photon) on Mac
I want to install PHP 7.2 on Ubuntu 20.04.
How to install beta php8.0 on CentOS8
How to change the timezone on Ubuntu
How to install kafkacat on Amazon Linux2
How to Install Oracle JDK 1.8 in Ubuntu 18.04 LTS?
[Ruby on Rails] How to install Bootstrap in Rails
How to build a Pytorch environment on Ubuntu
How to log in automatically when Ubuntu restarts
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
How to install Ruby on an EC2 instance on AWS
How to install geckodriver (Selenium WebDriver) automatically using WebDriverManager
Install MySQL 5.6 on CentOS6 [How to specify the version]
Install pyqt5 on ubuntu
Install Ruby on Ubuntu 20.04
How to install Docker
How to install docker-machine
Install Autoware on Ubuntu 18.04.5
How to install MySQL
Install Homebrew on Ubuntu 20.04
How to install ngrok
How to run npm install on all projects in Lerna
How to Burning a Install Disk of Windows from Ubuntu
How to install JDK 8 on Windows without using the installer
How to install GNOME as a desktop environment on CentOS 7
Install OpenJDK7 (JAVA) on ubuntu 14.04
Install Cybozu Office 10 on Ubuntu 20.4
Install Docker on Ubuntu Server 20.04
[Rails] How to install devise
How to deploy on heroku
Install zabbix agent (5.0) on Ubuntu 18.04
Install MAV Proxy on Ubuntu 18.04
Install Arudino IDE on Ubuntu 20
Install Java on WSL Ubuntu 18.04
How to install Boots Faces
Install Ubuntu Desktop 20.10 on RaspberryPi4
Install Arduino IDE on Ubuntu 20.04
Install raspi-config on Ubuntu 20.04 (LTS)
Install WordPress 5.5 on Ubuntu 20.04 LTS
Install PlantUML on Intellij on Ubuntu
Install Ubuntu Server 20.04 on Btrfs
Note: Install PostgreSQL 9.5 on Ubuntu 18.04
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
How to install JDK8-10 (Mac)