2010年8月19日木曜日

conversion linux -> OSX

研究所のサーバー環境(Linux : Enterprise5/Fedora)から、家の環境(MAC OSX)で既存のprogramが走るように変更して遊んでみました。

以下にdebug logを記載

[Error1]
error: conflicting declaration ‘typedef long int suseconds_t’
darwinに宣言が存在するようなので、宣言を削除


[Error2]
error: mntent.h: No such file or directory
error: sys/statfs.h: No such file or directory
error: ‘setmntent’ was not declared in this scope
error: ‘getmntent’ was not declared in this scope
今回最も面倒だったerrorですね。
mount情報にアクセスしたいのですが、OSXではgetmntent、setmntent、addmntent、endmntent、hasmntopt関数はサポートされていません。
既存のcodeでは、/etc/mtab.tmp, /etc/mtab, /proc/mountsの中の最新情報でファイルシステム、pass等を上書きします。

そもそもOSXはprocファイルシステムが存在しない上に、互換性のあるlibraryも見つかりません。
少し詳しく調べてみるとgetmntinfo()が使えそうです。

そこでmntent.h、sys/statfs.hを外して、sys/mount.hをインクルードします。そして以下のようにsourceを変更。

59 struct statfs *mntbuf;
60 if( getmntinfo( &mntbuf, MNT_NOWAIT) ) {
61 device = mntbuf->f_fstypename;
62 mnt_dir = mntbuf->f_mntonname;
63 }


[Error3]
error: ‘umount’ was not declared in this scope
sys/mount.hを見てみると関数名が違う。
umount( mnt.c_str() ) から unmount( mnt.c_str(), 0 )へ変更。



[Error4]
error: ‘IUCLC’ was not declared in this scope
sys/termios.hを見てみると、IUCLCが定義されていない。
GPS関連の端末制御は今重要ではないので、とりあえずsourceから削除。



[Error5]
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [/Users/sakaikenichi/workspace/bess/plib/lib/libBessP.so] Error 1

このerrorも若干はまりました。
まず、検索して多くhitしたのが、64bit環境における32bit版のlibraryに起因する問題です。32bit固定してmakeしても問題は取り除けませんでした。

どうにもこのerror messageは、main()が見つかりませんと言っているようです。
いや、libraryを作るんだからmain関数はなくて良いんだと思っていると、-sharedがOSXで使えないとの情報が…。

-shared
Produce a shared object which can then be linked with other objects to form an
executable. Not all systems support this option. For predictable results, you
must also specify the same set of options that were used to generate code
(-fpic, -fPIC, or model suboptions) when you specify this option.[1]

This option is not supported on Mac OS X.

本当でした。shared optionをdynamiclibに変更して問題解決。


[Error6]
error: ‘O_LARGEFILE’ was not declared in this scope
確かに、sys/fcntl.hを見ても無いですね。かなり嫌な感触を受けますが、とりあえず削除。
OSXは元から64bitのファイルを扱えるからflagが存在しないのか、patch等を当てなければならないのか調べていません。
差し当たって問題は無いのですが、2GB以上のファイルでerrorが吐かれないか留意します。