Linux (old) Newbies

古いWindows環境からLinux環境へと移り住んだ日々の出来事

Ubuntu 24.04 でアプリを初めてビルドした

Linux環境に乗り換えてから特に不都合もなくビルド済みのアプリを利用することで事足りているのですが、オープンソースの世界だから、やっぱり自前でソースコードからいつかはビルドする場面が来るだろうと思っていました。そんな折、必要に迫られるような状況ではないけれど、ふとしたきっかけでどうやってビルドするのだろう? と、必要なツールなどを見てみたところ、GCC とか make など殆どが最初から Ubuntu 環境には入っているようなので少し整備するだけでビルドができそうに感じられたので思い立って、やってみることにしました。

ビルド対象は、とあるネトゲ(?)のクライアント

ネトゲのクライアントをビルドというのは不思議に思うところかもしれませんが、オープンソースで提供されているタイトルの1つの 「Second Life」 のビルドにチャレンジなのです。

secondlife.com

この Second Life のクライアントソフト(ビュワーと呼ばれます)は、公式サイトが提供するものや、オープンソース故に改変したものなど色々と公開されています。そんな中、Linux 向けのクライアントソフトは現在は公式からの提供はなく、第三者が制作した物のみとなっています。いくつか Linux 対応がある中で、私がビルド対象としたのは 「Cool VL Viewer」 です。

sldev.free.fr

 

Cool VL Viewer のLinux版ビルドに必要な環境

The tools required to build the viewer are:
 - gcc/g++ v8.1 or newer (1), or clang/clang++ v7.0 or newer (2), that is a
   full-fledged C17/C++17 compiler.
 - binutils (as, ld & Co) and optionally elfutils (for eu-strip)
 - make
 - cmake (v3.10 or newer); v3.16+ recommended for a much faster compilation.
 - python (v3.3 or newer)
 - tar, bzip2 and gzip
 - bash
 - grep (for the linux-build.sh script)
 - coreutils (for the linux-build.sh script)

You will also need:
 - The headers and shared libraries for glibc v2.28 or newer.
 - The headers and shared libraries for libstdc++ v6.0.25 or newer.
 - The headers and libraries for X11, Xrender, Xinerama, OpenGL, Mesa (GL/GLU).
 - A working connection to Internet for the automatic retrieval of the
   pre-built libraries (note that once those libraries are cached on your
   build system (3), the connection is no more necessary).

なんだか色々と必要そうだけど、よく見ると Ubuntu に最初から入っていそうなものもチラホラと伺えるのが、もしかしなくても簡単に出来そうだと感じたのです。

既にインストールされていたもの (Ubuntu 24.04 LTS + Xfce)

gcc --version                      // 13.3.0
ldd --version                      // (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39
apt list|grep binutils|grep イン   // 2.42-4
make --version                     // GNU Make 4.3
python3 --version                  // 3.12.3
bash --version                     // GNU bash 5.2.21
grep --version                     // GNU grep 3.11
apt list|grep coreutils|grep イン  // 9.4.3
apt list|grep libstdc|grep イン    // 13.3.0 (dev も入っていた)

無かったので追加したもの

# Cmake
sudo apt install cmake

# X11 libraries
sudo apt install libx11-dev

# libxrender libraries
sudo apt install libxrender-dev

# libxinerama
sudo apt install libxinerama-dev

# opengl
sudo apt install libopengl-dev

# mesa
sudo apt install mesa-common-dev

そしてビルドしてみたら・・・

なにも変更していないのにエラーというか Warning で止まってしまいました。😅😅😅
調べてみたところ、どうも GCC の v11 以降では、おせっかいな、ここって変じゃない?みたいな解析をする機能があるらしく、それに引っかかる箇所があるみたいだと理解しました。

Warning を無視するオプションを付けて再度ビルドで難なく完了。

最後での LINK のところでも Warning が出ていたけれど、大丈夫なのでしょう。


統合開発環境の導入はしていない

まずは自分の PC でビルドできる環境を得るところまで来ました。
Windows を使っていたときのように統合開発環境(IDE)としたいところですが、なにが良いのやらさっぱり分かりません。 Windows 環境では Microsoft の Visual なんたらな環境で、楽々でしたね。まぁ、そのへんは、おいおいやっていきたいです。

とりあえず、IDEは無くて手打ちのコマンドラインでのビルドですが、そのまま同じバイナリとはならないように、ちょっとばかり変更しています。

GCC v8系 → v13系
コンパイル
SSE2指定 → SSE4.1指定

としたころ、元の公開アプリでは付いていたオプションの一部がなくなっていました。
単に GCC のバージョンが違うからなのかな? まだまだ分からない事だらけです。

なくなったオプションは
-fsched-pressure -frename-registers -fweb -fira-hoist-pressure
この4つです。
バージョンは違うけれど GNU のサイトで解説を見ることができました。

gcc.gnu.org

-fsched-pressure
    Enable register pressure sensitive insn scheduling before register allocation. This only makes sense when scheduling before register allocation is enabled, i.e. with -fschedule-insns or at -O2 or higher. Usage of this option can improve the generated code and decrease its size by preventing register pressure increase above the number of available hard registers and subsequent spills in register allocation.


-frename-registers

    Attempt to avoid false dependencies in scheduled code by making use of registers left over after register allocation. This optimization most benefits processors with lots of registers. Depending on the debug information format adopted by the target, however, it can make debugging impossible, since variables no longer stay in a “home register”.
    Enabled by default with -funroll-loops.


-fweb

    Constructs webs as commonly used for register allocation purposes and assign each web individual pseudo register. This allows the register allocation pass to operate on pseudos directly, but also strengthens several other optimization passes, such as CSE, loop optimizer and trivial dead code remover. It can, however, make debugging impossible, since variables no longer stay in a “home register”.
    Enabled by default with -funroll-loops.


-fira-hoist-pressure

    Use IRA to evaluate register pressure in the code hoisting pass for decisions to hoist expressions. This option usually results in smaller code, but it can slow the compiler down.
    This option is enabled at level -Os for all targets.

 

ただリビルドしただけで効果は感じられました

なんとなくだけど描画のキレが良くなった気がします。やや間が空く感じでモッサリした描画だったのがすっきりくっきりってところでしょうか。気の所為レベルかもしれません。状況によっては改悪となっているかも・・・。描画が速いに越したことはないけれど、まずは正しく動作しないと意味がないので使い続けて問題が出ないことを祈るばかりです。