[ Home | Programming Tips | Mail ]

STLport on CWPro2


CodeWarrior Pro2で SGI STLを使う

 現在出回っている STLの実装中、色々な環境で使い込まれ(叩かれて)品質では定評のある SGI版 STLを CW Pro2に Portしてみました。(と言ってもほとんど Porting済みの物があるのですが)

 方針としては #include pathの順序等を面倒に設定しなくても普通に '{Compiler}:Metrowerks Standard Library:' を Projectの System Pathsに 追加するだけで SGI版 STLが使える様にします。

(1) まず最新の STLportを Downloadします。

"Standard Template Library Adaptation Page"
http://www.metabyte.com/~fbp/stl/index.html から
http://www.metabyte.com/~fbp/stl/STLport-3.01.zip
を落してきて Unzipします。
 ちなみに本家 SGIの STL Pageはこちら
http://www.sgi.com/Technology/STL/

(2) Unzipした SGI版 STLは
 '{Compiler}:Metrowerks Standard Library:STLport-3.01:'
に置きます。

(3) SGI版 STLと重複している MSLの fileを隠します。
 '{Compiler}:Metrowerks Standard Library:MSL C++:Include:Library Support:' folder内の以下の fileを移動するか archiveして隠します。

    algorithm       hashmset.h    memory       stack
    algorithm.h     hashset.h     mmemory.h    stack.h
    deque           hashtbl.h     numeric      tree
    deque.h         heap.h        numeric.h    tree.h
    functional      iterator      queue        utility
    functional.h    list          queue.h      utility.h
    hashfun.h       list.h        set          vector
    hashmap.h       map           set.h        vector.h
    hashmmap.h      map.h         slist.h
(4) MSLの file名を変更
 '{Compiler}:Metrowerks Standard Library:MSL C++:Include:Library Support:' folder内の以下の file名を変更します。
    algobase.h --> algobaseMSL.h
    iterator.h --> iteratorMSL.h
(5) SGI版 STLで修正が必要な fileは以下の通り
    msl_algobase.h   46行目
        # else
        // Typical Mac installation
        #include    <algobaseMSL.h>     // MSLの fileを指定
        # endif
    msl_iterator.h   61行目
        # else
        // Typical Mac installation
        #include    <iteratorMSL.h>     // MSLの fileを指定
        # endif
    stlcomp.h        32行目
        // Uncomment that to to use new-based allocator as default
        #  define    __STL_USE_NEWALLOC   1         // 生かす
    stlcomp.h        458行目
        // Metrowerks CodeWarrior
        # if defined (__MWERKS__)
        #  define __STL_TRIVIAL_DESTRUCTOR_BUG  1   // 追加
    stl_tempbuf.h
        絶対修正が必要というわけではないが、malloc()と newを両方
        使うと両者が Poolを確保して memoryの無駄使いなので C++らしく
        newに統一する。
        #include    <new>       // 追加
        xx = (T*) malloc(len * sizeof(T));
            -->  xx = (T*)::operator new((size_t)len * sizeof(T),nothrow);
        free((char*)xx);
            --> ::operator delete(xx);
(6) MSL C++ Libraryを Rebuildします。
 '{Compiler}:Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C++:Bin:' folder内の C++ Libraryを既存の Projectを流用して Rebuildします。
Projectに必要なのは以下の fileです。
    complex.cpp
    facet.cpp
    iostream.cpp
    iomanip.cpp
    locimp.cpp
    mlimits.cpp
    inst1.cpp
    inst2.cpp
 MSL C++ Libraryに代えて上記の fileを Projectに加えても構いませんが、 一々 Compileするので遅くなります。

 以上で Projectの System Pathsへの
 '{Compiler}:Metrowerks Standard Library:' 追加と (6)で Rebuildした MSL C++ Libraryの追加で SGI版 STLが使えるはずです。

 "Standard Template Library Adaptation Page"に Testing Suiteもありま すので試してみましょう。(目茶苦茶でかい Projectになりますが...)

http://www.metabyte.com/~fbp/stl/test.zip

この Pageは MacOS X + Radio UserLand で作っています。