mokky14's IT diary

IT関係の仕事メモ、勉強会の感想など書いてます。

CUnitをSolarisにインストールしてみた

CUnitをSolarisにインストしてみたので、そのメモ。

このブログ執筆時点でCUnitの最新版は2.1-2だったが、
Adding Unit Tests to a C Project - NetBeans IDE Tutorialのサイトに以下の記述を見つけた。

Install the CUnit Testing Framework

To follow this tutorial, you must install CUnit on your system first. You can download the CUnit framework from the C Unit Testing Framework project on sourceforge.

The CUnit files page includes links to binary downloads for Windows and Linux.

For Solaris systems, you must download the CUnit-2.1-0-src.tar.gz source from the CUnit files page and use the GNU build system to build the source and install. You can get the GNU build system components autoconf and automake for Solaris from sunfreeware.com.

The CUnit documentation is included in the CUnit download, or you can view it at http://cunit.sourceforge.net/doc/index.html.

なお、この記事を見つける前に、CUnitの最新版(2.1-2)をダウンロードしてインストしたときは、

 $ configure
 $ gmake
 # gmake install

でインストは出来たが、インスト先のinclude/CUnitディレクトリ配下に CUError.h しか展開されなかった。


ということで、CUnit-2.1-0-src.tar.gzをダウンロード。
GNU build systemは多分一通り入ってるはず。
autoconfとautomakeはpkgutilでインスト済なので、それを使う。

以下手順でインスト。64bit用にするため、CFLAGに-m64を指定。インストール先は /usr/local/cunit64 配下にした。

bash-3.2$ gtar xvzf CUnit-2.1-0-src.tar.gz
bash-3.2$ cd CUnit-2.1-0
bash-3.2$ ./configure --prefix=/usr/local/cunit64 CFLAGS=-m64
bash-3.2$ gmake
bash-3.2$ su
# bash
# gmake install

インスト完了。

Sun Studio 11でのコンパイルでも動作するか確認してみる。
確認するソースは、ここの内容を丸パクリした。

bash-3.2$ /opt/SUNWspro/bin/cc -L/usr/local/cunit64/lib -lcunit -I/usr/local/cunit64/include -xtarget=generic64 -o cunit_test cunit_test.c
bash-3.2$ ./cunit_test
ld.so.1: cunit_test: 重大なエラー: libcunit.so.1: open に失敗しました: ファイルもディレクトリもありません。
強制終了
bash-3.2$ export LD_LIBRARY_PATH=/usr/local/cunit64/lib
bash-3.2$ ./cunit_test


     CUnit - A Unit testing framework for C - Version 2.1-0
     http://cunit.sourceforge.net/


*************** CUNIT CONSOLE - MAIN MENU ***********************
(R)un all, (S)elect suite, (L)ist suites, Show (F)ailures, (Q)uit
Enter Command : R

Running Suite : Sort
        Running test : test_001
        Running test : test_002
        Running test : test_003
        Running test : test_004
        Running test : test_005

--Run Summary: Type      Total     Ran  Passed  Failed
               suites        1       1     n/a       0
               tests         5       5       5       0
               asserts      31      31      31       0

*************** CUNIT CONSOLE - MAIN MENU ***********************
(R)un all, (S)elect suite, (L)ist suites, Show (F)ailures, (Q)uit
Enter Command : Q
bash-3.2$