コグノスケ


link 未来から過去へ表示(*)  link 過去から未来へ表示

link もっと前
2019年1月23日 >>> 2019年1月14日
link もっと後

2019年1月18日

Cocos2d-x再び

以前Cocos2d-xをビルドして(2017年6月30日の日記参照)、Linuxで動くサンプルプログラムをビルドしました。あの時は結局、ゲームは作らずじまいでした。懲りずに、今回はAndroid向けにビルドします。

その前にまずLinux向けにビルドします。簡単かと思ったら、めちゃくちゃハマりました……。

ビルドできないCocos2d-x

公式ドキュメント(リンク)に載っている通りの手順を試すと、下記のようなエラーが出ます。

Cocos2d-xのビルドエラー
$ git clone https://github.com/cocos2d/cocos2d-x
$ cd cocos2d-x/


$ git submodule update --init
Submodule path 'tests/cpp-tests/Resources/ccs-res': checked out '5d65db4c5f18c0df1305ff32b076425ab228cc4a'
Submodule path 'tools/bindings-generator': checked out '2aa9b21f11bf514ca80f243b21750e8c7c28f05e'
Submodule path 'tools/cocos2d-console': checked out '643f423415c62a1b610549323c4bf5499683baab'
Submodule path 'web': checked out 'e79acd062363818af809c51804083a5989a9aedc'


$ ./download-deps.py
=======================================================
==> Prepare to download external libraries!
==> version file doesn't exist
==> Ready to download 'v3-deps-156.zip' from 'https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin/archive/v3-deps-156.zip'
(...snip...)
==> Would you like to save 'v3-deps-156.zip'? So you don't have to download it later. [Yes/no]: Yes


$ cd build/
$ mkdir linux-build
$ cd linux-build/


$ cmake ../../
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/lib/ccache/cc
-- Check for working C compiler: /usr/lib/ccache/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
(...snip...)
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/katsuhiro/share/projects/oss/cocos2d-x/build/linux-build


$ make
[  0%] Building CXX object engine/external/unzip/CMakeFiles/ext_unzip.dir/ioapi.cpp.o
[  0%] Building CXX object engine/external/unzip/CMakeFiles/ext_unzip.dir/unzip.cpp.o
[  0%] Building CXX object engine/external/unzip/CMakeFiles/ext_unzip.dir/ioapi_mem.cpp.o
[  1%] Linking CXX static library ../../../lib/libext_unzip.a
(...snip...)
[ 84%] Built target jscocos2d
[ 84%] Building CXX object engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/Classes/AppDelegate.cpp.o
[ 84%] Building CXX object engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/Classes/HelloWorldScene.cpp.o
[ 84%] Building CXX object engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/proj.linux/main.cpp.o
[ 84%] Linking CXX executable ../../../bin/Debug/cpp-empty-test/cpp-empty-test
/usr/bin/ld: ../../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
(...snip...)
/usr/bin/ld: ../../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftbitmap.linux64.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[2]: *** [engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/build.make:153: bin/Debug/cpp-empty-test/cpp-empty-test] Error 1
make[1]: *** [CMakeFiles/Makefile2:1362: engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

エラーで指摘されているfreetype2/prebuilt/linux/64-bit/libfreetype.aは、download-deps.pyがダウンロードしてきたv3-deps-156.zipに含まれているスタティックライブラリです。recompile with -fPICと言われても、自分でビルドしたものではないので、何もできません。そんなこと言われても困る。

困った挙句にCocos2d-xのissue list(リンク)に辿りつきました。議論を見るとcocos2d-x-3rd-party-libs-srcリポジトリのbuild.shでライブラリが作れるみたいです。うえ〜、そんなの知らんがな。

Cocos2d-xの依存ライブラリビルド
$ git clone https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src
$ cd cocos2d-x-3rd-party-libs-src/build/

$ ./build.sh -p=linux --libs=freetype --arch=x86_64 --mode=release

$ cp linux/freetype/prebuilt/x86_64/libfreetype.a ../../cocos2d-x/external/freetype2/prebuilt/linux/64-bit/libfreetype.a

依存ライブラリを自前でビルドして置き換えることで、無事にCocos2d-xのコンパイルが通りました。

Cocos2d-xのゲームプロジェクトは簡単に作れた

心配だったゲームプロジェクトの作り方は以前と同じ2017年7月2日の日記参照)でした。こちらはハマらなくて本当に良かったです。

生成されたゲームプロジェクトの中にproj.androidという名前のディレクトリが作成されます。Android Studioでproj.androidを開けば後は勝手にGradleがビルドしてくれるはずです。

ゲームプロジェクトのトップ階層
$ ls
CMakeLists.txt  Resources  proj.android  proj.linux
Classes         cocos2d    proj.ios_mac  proj.win32

Linux向けにビルドしたいときは、以前と同じ手順でOKです。同じコードでAndroidもLinuxも対応できて便利ですよね。

編集者:すずき(2019/01/20 00:16)

コメント一覧

  • コメントはありません。
open/close この記事にコメントする



2019年1月14日

家のPC性能表、更新

昔(2017年5月2日の日記参照)作った我が家のPCのPassmarkスコア表に、Ryzen 7デスクトップ(2018年12月1日の日記参照)も加えました。

用途 CPUシングルマルチコア、スレッド数TDP
デスクトップ AMD Ryzen7 2700 2005149858C16T65W
旧デスクトップAMD A10-7800 15375069 4C4T 65W
ノート Intel Core i5 2450M14043404 2C4T 35W
サーバ Intel Pentium J4205899 2394 4C4T 10W
旧サーバ Intel Atom D2700 349 840 2C4T 10W
サブマシン Intel Atom D525 284 701 2C4T 13W

2年前はRyzen 7の8コアを欲しいなと思いつつも、何に使うか疑問に思っていましたが、Linuxのビルドに最適だということがわかって、とても役に立っております。買って良かった。

編集者:すずき(2022/01/28 14:43)

コメント一覧

  • コメントはありません。
open/close この記事にコメントする



link もっと前
2019年1月23日 >>> 2019年1月14日
link もっと後

管理用メニュー

link 記事を新規作成

<2019>
<<<01>>>
--12345
6789101112
13141516171819
20212223242526
2728293031--

最近のコメント5件

  • link 21年3月13日
    すずきさん (03/05 15:13)
    「あー、このプログラムがまずいんですね。ご...」
  • link 21年3月13日
    emkさん (03/05 12:44)
    「キャストでvolatileを外してアクセ...」
  • link 24年1月24日
    すずきさん (02/19 18:37)
    「簡単にできる方法はPowerShellの...」
  • link 24年1月24日
    KKKさん (02/19 02:30)
    「追伸です。\nネットで調べたらマイクロソ...」
  • link 24年1月24日
    KKKさん (02/19 02:25)
    「私もエラーで困ってます\n手動での回復パ...」

最近の記事20件

  • link 24年3月19日
    すずき (03/20 02:52)
    「[モジュラージャックの規格] 古くは電話線で、今だとEthernetで良く見かけるモジュラージャックというコネクタとレセプタク...」
  • link 23年4月10日
    すずき (03/19 11:48)
    「[Linux - まとめリンク] 目次: Linuxカーネル、ドライバ関連。Linuxのstruct pageって何?Linu...」
  • link 24年3月18日
    すずき (03/19 11:47)
    「[画面のブランクを無効にする] 目次: LinuxROCK 3 model CのDebian bullseyeイメージは10分...」
  • link 24年3月3日
    すずき (03/19 11:07)
    「[解像度の設定を保存する] 目次: LinuxRaspberry Pi 3 Model B (以降RasPi 3B)のHDMI...」
  • link 24年3月14日
    すずき (03/16 23:03)
    「[JavaとM5Stamp C3とBluetooth LE - Bluetoothデバイスとの通信] 目次: ArduinoM...」
  • link 24年3月8日
    すずき (03/16 23:03)
    「[JavaとM5Stamp C3とBluetooth LE - BluetoothデバイスとServiceの列挙] 目次: A...」
  • link 23年6月2日
    すずき (03/16 21:11)
    「[Arduino - まとめリンク] 目次: Arduino一覧が欲しくなったので作りました。 M5Stackとesp32とA...」
  • link 23年5月15日
    すずき (03/16 00:57)
    「[車 - まとめリンク] 目次: 車三菱FTOの話。群馬県へのドライブ将来車を買い替えるとしたら?FTOのオイル交換とオイル漏...」
  • link 24年3月9日
    すずき (03/16 00:56)
    「[車のバッテリー完全に死亡で交換かと思いきや] 目次: 車またまた車のバッテリーが干上がって死にました。写真は撮っていませんが...」
  • link 24年3月10日
    すずき (03/15 03:34)
    「[誕生日] 早いもので41歳になりました。昨年の日記(2023年3月10日の日記参照)を見ると、コロナの流行を心配していました...」
  • link 24年3月6日
    すずき (03/12 01:18)
    「[Raspberry Pi 3 model Bの代わりにROCK 3 model C] 目次: Arduino最近、M5Sta...」
  • link 24年3月4日
    すずき (03/06 00:09)
    「[volatileをnon-volatileで参照してはいけない] 目次: GCC過去の日記(2021年3月13日の日記参照)...」
  • link 20年6月2日
    すずき (03/06 00:06)
    「[GCC - まとめリンク] 目次: GCCGCCについて。GCCを調べる - その1 - ビルドGCCを調べる - その2 ...」
  • link 15年5月9日
    すずき (03/05 03:00)
    「[自作ARMエミュレータ - 今さら気づいたブートローダのバグ] 目次: Linuxずっと気づいていなかった自作ARMエミュレ...」
  • link 23年6月1日
    すずき (03/05 02:59)
    「[自宅サーバー - まとめリンク] 目次: 自宅サーバーこの日記システム、Wikiの話。カウンターをPerlからPHPに移植日...」
  • link 15年5月3日
    すずき (03/05 02:59)
    「[GRUB2が起動しなくなってしまった] 目次: 自宅サーバーサーバにインストールしていたDebian 32bit版 のJes...」
  • link 15年5月2日
    すずき (03/05 02:58)
    「[systemdを使うのをあきらめた] 目次: 自宅サーバー独自ビルドのカーネルだと/sys/fs/cgroupが無いと言われ...」
  • link 15年4月30日
    すずき (03/05 02:56)
    「[Debian 8.0 Jessie] 目次: 自宅サーバーDebianのアップデートが来ていたので、試しに職場のPCをアップ...」
  • link 15年3月6日
    すずき (03/05 02:55)
    「[SysV initの処理変更(直列版)] 目次: Linux昨日(2015年3月5日の日記参照)に引き続き、何となく自分では...」
  • link 15年3月2日
    すずき (03/05 02:54)
    「[自作ARMエミュレータ - アイドル処理] 目次: Linux自作ARMエミュレータのアイドル状態を実装して、何もしていない...」
link もっとみる

こんてんつ

open/close wiki
open/close Linux JM
open/close Java API

過去の日記

open/close 2002年
open/close 2003年
open/close 2004年
open/close 2005年
open/close 2006年
open/close 2007年
open/close 2008年
open/close 2009年
open/close 2010年
open/close 2011年
open/close 2012年
open/close 2013年
open/close 2014年
open/close 2015年
open/close 2016年
open/close 2017年
open/close 2018年
open/close 2019年
open/close 2020年
open/close 2021年
open/close 2022年
open/close 2023年
open/close 2024年
open/close 過去日記について

その他の情報

open/close アクセス統計
open/close サーバ一覧
open/close サイトの情報

合計:  counter total
本日:  counter today

link About www2.katsuster.net
RDFファイル RSS 1.0

最終更新: 03/20 02:52