http://sourceforge.net/p/stlport/code/ci/STLport-5.2/tree/

去抓最新版,有cmake
裡面的靜態記得要 _STLP_USE_DYNAMIC_LIB 的定義喔~
編完後~

如果想用 stlport 取代掉 目前預設的 stl 就取代就好
現在要講的是如何兩套 stl 並存
我會假設看的人都會設程式庫路徑跟標頭檔路徑

先定義這兩行別的 stlport 跟內建的 stl 衝突
#define _STLP_USE_OWN_NAMESPACE 1
#define _STLP_DONT_REDEFINE_STD 1

加入 include 檔
#include <stlport/vector>

如果有使用 boost 還要加下面兩行免的 auto link 到錯的 boost lib
#undef __SGI_STL_PORT
#undef _STLPORT_VERSION

最後連結你編好的 lib 檔
_STLP_USE_STATIC_LIB 連結靜態
_STLP_USE_DYNAMIC_LIB 連結動態

使用某些檔案時會有模稜兩可的呼叫多載函式的問題發生
請幫 stlport 的函數加上 stlport::

範例程式:

#define _STLP_USE_STATIC_LIB
#define _STLP_USE_OWN_NAMESPACE 1
#define _STLP_DONT_REDEFINE_STD 1
#include <stlport/vector>
#include <stlport/iostream>
#include <stlport/algorithm>
#undef __SGI_STL_PORT
#undef _STLPORT_VERSION
#include <auto_link_stlport.hpp>

#include <iostream>
#include <algorithm>
#include <vector>


typedef stlport::vector<int> intsp;
typedef std::vector<int> ints;

int main(int argc, char* argv[])
{
    intsp ary1;
    ints  ary2;
    for (int i = 0; i < 10; ++i)
    {
        ary1.push_back(i);
        ary2.push_back(i);
    }
    for (intsp::iterator it = ary1.begin(); it != ary1.end(); ++it)
    {
        std::cout << *it;
        stlport::cout << *it << " ";
    }
    stlport::cout << stlport::endl;
    std::random_shuffle(ary1.begin(), ary1.end());
    stlport::random_shuffle(ary2.begin(), ary2.end());
    for (int i = 0; i < ary2.size(); ++i)
    {
        std::cout << ary1[i];
        stlport::cout << ary2[i] << " ";
    }
    std::cout << std::endl;
    stlport::sort(ary1.begin(), ary1.end());
    //stlport::sort(ary2.begin(), ary2.end()); // error C2665
    std::sort(ary2.begin(), ary2.end());
    for (int i = 0; i < ary2.size(); ++i)
    {
        std::cout << ary1[i];
        stlport::cout << ary2[i] << " ";
    }
    return 0;
}

arrow
arrow
    全站熱搜

    讓地獄深紅的天亮 發表在 痞客邦 留言(0) 人氣()