STLport安装指南

STLport安装指南
STLport-4.6 是完全兼容ANSI C++标准的类库。

This distribution contains STLport sources only, no binaries.
To use STLport iostreams, you have to build STLport library from sources in "src"
directory and link your programs with it.
这个发布包仅仅包括STLport源代码马,不含二进制发布软件包。必须重新编译src目录下的代码才可以使用STLport iostreams类库。
This is major change since pre-4.0 releases, please read the instructions carefully.
这是自4.0版本发布以来的重要变更版本,请仔细的阅读下面的操作指南。

==== Unpacking and installing STLport ==========
解包和安装STLport

1) Unpack STLport archive to a directory accessible during compilation.
   NOTE : DO NOT overwrite header files coming with the compiler, even if you made
   a backup - this won't work ! Most probably, you've already unpacked the archive before
   reading this file though ;)
首先吧STLport安装包解压缩到一个目录。注意:不要覆盖了编译器自带的头文件,即使你已经做了备份,也不要这么做!
2) Make sure "stlport" directory of this distribution comes before compiler's one
   in your search path when you compile the project;
确保stlport目录在编译器自带的头文件搜索路径之前
   Note: for SunPro CC 5.0 and higher, there used to be special directory "stlport/SC5"
  this is now obsolete, please make sure you do not use it anymore.
注意:对于SunPro CC 5.0或者更高版本,有一个特殊的目录stlport/SC5,这个目录已经背废弃了,请不要再使用这个目录。
3) Make sure you do not rename this "stlport" subdirectory -
   that may result in compilation errors.
确保不要修改stlport的子目录名称,否则会导致编译错误
   NOTE : Do NOT attempt to run "configure" ! It is deprecated, moved to safe standalone folder
          and should be used as a helper to create initial config for a new compiler only.
          Your compiler should be recognized by STLport source code with no configuring.
   Please edit appropriate configuration header for your compiler
          directly if you have to make compiler-specific configuration changes.
注意:不要尝试运行configure命令,该方法已经废弃不用了,已经移到一个安全单独的目录,只能用于作为为新编译器的创建初始配置的辅助手段。您使用的编译器应该能够被STLport的源代码识别,如果需要针对您使用的编译器进行特殊的配置,请直接修改适当的头文件。

4)  Go to "src" subdirectory. It contains various makefiles for different
    compilers.  If you are not able to find makefile for your particular
    compiler, please use one that looks most similar to your make engine to
    create your own.
直接进入src目录,这个目录包含了各种不同编译器使用的make文件,请选择一个和你的编译器相似的make文件。
    Verify you can do command line compiles. IDE users may have to do something
    special, like add environment variables (for Microsoft) or install
    additional compiler components (for Metrowerks), before they can use their
    command line compilers.
必须在命令行方式编译,使用IDE编译需要设置一些环境变量(微软)或者安装特殊的编译组件(Metrowerks)。
   IMPORTANT :

   If you DO NOT plan to use STLport iostreams implementation, you do not have to build the library.
   Please do this instead  :
如果你不需要使用STLport iostream类库,你不必编译整个类库,请使用下面的方法
   4-1) Using appropriate makefile, do "make -f <your compiler name>.mak prepare".
    Please do not skip this! On some platforms, it creates necessary symbolic links.
        If you do build STLport iostream, this step is performed automatically when you do "make all".
使用适当的make文件,执行“make -f <your compiler name>.mak prepare”命令,不要跳过这步!在一些平台上,它创建了一些符号链接。在需要编译STLport库时,这个步骤是由“make all”自动完成的
   4-2) uncomment _STLP_NO_OWN_IOSTREAMS setting in "stlport/stl_user_config.h" to disable use
       of STLport iostreams and to use wrappers around your existing iostreams.
       After disabling STLport iostreams, you will use wrappers around  your compiler's iostreams
       libabry, as in previous STLport releases.
       No binary library for STLport needs to be built in this case.
       Note though :
        - new-style ANSI iostreams may not be available on your system;
        - compiler's iostreams are most likely slower than STLport version.
删除stlport/stl_user_config.h文件中_STLP_NO_OWN_IOSTREAMS编译常量的注释禁止使用STLport iostream类库,并且使用已经存在的iostream类库的封装类。在这种情况下不需要重建STLport二进制类库。
 
  If you have decided to disable STLport iostreams, you may stop reading here.
如果你已经决定不使用STLport iostream类库,可以不用往下阅读了。

==== Building STLport iostreams library ==========

Below are step-by-step instructions to build STLport streams library:
下面是一步一步的教你编译STLport stream类库

5)  Using appropriate makefile, do "make clean all" to build the STLport libraries
    (makefiles are set up to build several different flavors - debug/nondebug,
    static/dynamic versions).
    Optionally, do "make install" to copy STLport headers and libraries to shared location.
选择适当的make文件,执行make clean all编译STLport库,make文件设置了集中不同的编译方式-debug/nondebug和static/dynamic版本。可选的,执行make install拷贝STLport的头文件和库文件到共享的位置。
    Note : your "make" program may have different name, like "nmake" for Visual C++.
注意:make文件可能有不同的名称,VC使用nmake
    Examples :
     1. If you are building STLport for just one compiler, you may do something like that
        (DOS syntax for Visual C++ below):
        copy vc6.mak makefile
        nmake clean all
        nmake install
例如:
 1.如果你只是为一种编译器编译STLport,方法如下:
 copy vc6.mak makefile
 nmake clean all
 nmake install

     2. If you plan to build STLport with multiple compilers, use "make -f" :
 make -f gcc.mak clean install
 make -f sunpro.mak clean install
        This will build and install STLport for gcc & SUN CC.
 2.为多个编译器编译STLport,使用make –f
 make -f gcc.mak clean install
 make -f sunpro.mak clean install
 这会编译和安装STLport gcc和SUN CC两个版本。

        "install" target works on most platforms.

 install编译依赖目标几乎在所有的平台上可以使用。

         On Win32, it does the following :
          - copies STLport headers in "stlport" subdirectory of your compiler's INCLUDE directory;
          - copies STLport .lib files in your compiler's LIB directory;
          - copies STLport DLLs to Windows system directory so they can be found at runtime.
 在Win32平台上,install目标做了下面的工作:
 -拷贝STLport的头文件到编译器的INCLUDE目录
 -拷贝STLport.lib到编译器的LIB目录
 -拷贝STLport DLL库到Windows的系统目录

  On UNIX, it does the following :
          - copies STLport headers in "stlport" subdirectory of system's local include directory (default is /usr/local/include);
          - copies STLport .a and .so files to system local library directory (default is /usr/local/lib);
 在UNIX平台上,它完成了下面的工作
 -拷贝STLport头文件到系统local include目录(默认是/usr/local/include)
 -拷贝STLport.a和.so文件到系统的local库文件目录(默认为/usr/local/lib)
6)  If build fails, you may choose to :
     - try fixing the build ;
     - wait until somebody else will submit corresponding changes to be incorporated in next STLport
       release/snapshot. To use STLport w/o its own iostreams, please do step 3a).

    In case you do patch STLport, please submit your patches tosupport@stlport.com or (better)
    to STLport Forum (
http://www.stlport.com/cgi-bin/forum/dcboard.cgi)
如果编译失败,你可以:
-试着修改相关文件重新编译
-等待其他人发现同样的问题,这STLport的下个发布中修改
既然你已经为STLport打了补丁,请把你的补丁发送到
support@stlport.com或者(最好使用这种方式)STLport Forum(http://www.stlport.com/cgi-bin/forum/dcboard.cgi)
7) Do "make install" to install resulting libraries into "./lib" subdirectory.
 执行make install安装编译产生的库到/lib目录

==== Linking your application with STLport library ==========
链接应用程序到STLport库文件
8) Supply the "lib" subdirectory to the library search path and add desired
   library to the list of libraries to link with.
把lib目录加入到库文件的搜索路径中并且指定要链接的库名称。
   Examples (imagine you have mytest.cpp in the same directory as this file is):
 With gcc     : gcc -I./stlport mytest.cpp -L./lib/ -lstlport_gcc
 With DEC CC  : cxx -I./stlport mytest.cpp -L./lib/ -lstlport_deccxx
 With SUN CC  : CC -I./stlport mytest.cpp -L./lib/ -lstlport_sunpro
 .....
例如:
 -gcc,gcc -I./stlport mytest.cpp -L./lib/ -lstlport_gcc
 -DEC CC,cxx -I./stlport mytest.cpp -L./lib/ -lstlport_deccxx
 -SUN CC,CC -I./stlport mytest.cpp -L./lib/ -lstlport_sunpro
 ……
   [ Visual C++ specific ] For VC++, you do not have to specify "stlport-msvc-XXX.lib" explicitly,
   as it is being choosen and forced to link automatically by "#pragma"'s in stlport/config/stl_select_lib.h.
   Appropriate version is being selected based on /MD[d] vs /MT[d] options and __STL_DEBUG setting.
   All you have to do is to set library search path for the linker.
 Example :
           cl.exe /I./stlport mytest.cpp /link /libpath:./lib /MD
 -VC比较特殊,不需要显式的指定stlport-msvc-XXX.lib库文件,而是在stlport/config/stl_select_lib.h头文件中使用#pragma指令自动选择了链接的库文件。有些版本基于/MD[d] vs /MT[d]编译选项编译,以及设置了__STL_DEBUG编译常量。只需要按照下面的设置即可:
 cl.exe /I./stlport mytest.cpp /link /libpath:./lib /MD

9) If you linked your application with shared STLport library (.so or .dll), please make your .so or
   .dll's to be found in PATH at runtime. On Windows, the simplest way to do it
   is to copy all .dll's to Windows system directory. Or, you might choose to add directory
   containing STLport to the PATH environment string.

10) Have fun !

10/31/03, Boris Fomitchev.

 

----------------------------------------------------------------------------------------------------

 

 

stlport的主页是http://www.stlport.org/,以下讨论都是针对版本5.1.3

 

首先介绍一下关键的目录,假设解压后的目录为stlport-5.1.3stlport-5.1.3目录下的stlport目录提供了头文件,应用程序必须要将该目录放到头文件包含目录的最前面。stlport-5.1.3目录下的build/lib目录提供了生成不同平台下stlport库的配置文件。比如,在stlport-5.1.3/build/lib目录下运行“make -f gcc.mak dbg-static”即用gcc来编译debug版本的静态库,编译结果为obj/gcc/so_g/libstlportg.a,文件名中的g表示debug版本。

 

最终,只需要提供整个stlport-5.1.3/stlport头文件目录和库文件即可。

 

其他使用方法略,随便网上找找都可以找到。只需要记得必须将”-I …./stlport/stlprot/”放在编译参数的最前面,尽量将”-L…./libstlport.a”放在链接参数的最后面(如果使用linux的静态库的话),下面主要介绍在linux下的一些特殊用法。

 

linux下,可能会碰到不同系统中libstd++.so的不匹配问题,那么,我们就需要使用静态库。可是,有些时候,libstdc++.a无法满足要求。因此,我们选择使用stlport库和libsupc++.a来共同提供libstdc++.a的功能;某些时候,我们也可以对源代码作些调整,可以只使用stlport静态库(libc.a),而不包括supc++库。

 

以下的描述都是基于当前目录为stlport-5.1.3进行的讨论。

 

一.编译器选择

build/Makefiles/gmake/gcc.mak文件的开头增加以下设置,即可不使用系统默认编译器。

CC := 。。。

CXX := 。。。

LD := 。。。

AR := 。。。

 

二.编译选项修改

这里只是一般性的描述,具体描述将在下面结合具体需求进行,但不保证具体例子中编译选项修改的绝对准确,如果有问题,可以在下述文件中自行修改。

build/lib/gcc.mak

build/lib/Makefile.inc      (这个文件控制需要编译哪些源文件)

build/Makefiles/gmake/gcc.mak

 

一般的,可以在上述文件中增加一些宏定义,用来控制下面的修改启用与否。

为了达到一些目的,可以在build/Makefiles/gmake/gcc.mak 文件中为CXXFLAGS增加-fno-exceptions -fno-rtti选项。以及­-g或者­-O2等等。

 

三.避免使用exitabort函数

使用exitabort等函数会导致系统直接退出,在某些情况下是不允许的。

3.1 修改stlport/stl/_alloc.h的第55行,将exit退出修改为printf输出。

#ifndef __THROW_BAD_ALLOC

if !defined(_STLP_USE_EXCEPTIONS)

   ifndef _STLP_INTERNAL_CSTDIO

     include <stl/_cstdio.h>

   endif

   define __THROW_BAD_ALLOC printf("!!!!out of memory, exit in stlport library\n")

else

   define __THROW_BAD_ALLOC throw _STLP_STD::bad_alloc()

endif

#endif

3.2 修改stlport/stl/config/features.h文件第203行,将abort退出修改为printf输出

#ifndef _STLP_ABORT

define _STLP_ABORT() printf("!!!!!!!!!abort in stlport library")

#endif

 

四.取消使用exception

在一些底层应用中,不支持使用exception

4.1 stlport/stl/_exception.h文件中增加定义:

#define _STLP_NO_UNCAUGHT_EXCEPT_SUPPORT

4.2 stlport/stl/config/features.h文件中增加定义:

#define _STLP_HAS_NO_EXCEPTIONS

#define _STLP_DONT_USE_EXCEPTIONS

#define _STLP_NO_EXCEPTION_SPEC

#define _STLP_NO_UNCAUGHT_EXCEPT_SUPPORT

4.3 修改stlport/stl/­_stdexcept_base.h文件中修改第68行,移除继承的基类_STLP_EXCEPTION_BASE

class _STLP_CLASS_DECLSPEC __Named_exception  {

否则,当编译不链接stdlibc++库时,会提示找不到std::exception

 

五.移除pthread

对单线程的应用,并不需要pthread库,有些时候,也需要移除pthread的影响。

5.1 stlport/stl/config/host.h文件第11行附近启用定义:

#define _NOTHREADS

#define _STLP_NO_THREADS

5.2 build/Makefiles/gmake/gcc.mak文件中修改编译参数是否有­-pthread/-D_REENTRANT(这两个选项应该或者同时存在,或者同时不存在,记得是这样的吧)

 

六.移除local本地化和宽字符

6.1 修改build/lib/gcc.mak文件,将宏-D_STLP_REAL_LOCALE_IMPLEMENTED调整为-D_STLP_NO_LOCALE_SUPPORT

6.2 src/c_locale_glibc/c_locale_glibc2.c文件中的locale相关的字符函数strcoll_l, wcscoll_l换成字符函数strcmp, wcscmp

6.3 删除src/iostream.cpp文件第310行开始的被#ifndef _STLP_NO_WCHAR_T包围的代码:

  ptr_wcin->exceptions(0);

  ptr_wcout->exceptions(0);

  ptr_wcerr->exceptions(0);

  ptr_wclog->exceptions(0);

  delete ptr_wcin->rdbuf(0);

  delete ptr_wcout->rdbuf(0);

  delete ptr_wcerr->rdbuf(0);

  delete ptr_wclog->rdbuf(0);

  _Destroy(ptr_wcin);

  _Destroy(ptr_wcout);

  _Destroy(ptr_wcerr);

  _Destroy(ptr_wclog);

6.4 删除src/iostream.cpp文件第253行开始的被#ifndef _STLP_NO_WCHAR_T包围的代码:

    wistream* ptr_wcin  = new(&wcin)  wistream(0);

    wostream* ptr_wcout = new(&wcout) wostream(0);

    wostream* ptr_wcerr = new(&wcerr) wostream(0);

    wostream* ptr_wclog = new(&wclog) wostream(0);

    wfilebuf* win  = _Stl_create_wfilebuf(stdin, ios_base::in);

    wfilebuf* wout = _Stl_create_wfilebuf(stdout, ios_base::out);

    wfilebuf* werr = _Stl_create_wfilebuf(stderr, ios_base::out);

    wfilebuf* wlog = _Stl_create_wfilebuf(stderr, ios_base::out);

    ptr_wcin->init(win);

    ptr_wcout->init(wout);

    ptr_wcerr->init(werr);

    ptr_wclog->init(wlog);

    ptr_wcin->tie(ptr_wcout);

ptr_wcerr->setf(ios_base::unitbuf);

6.5 删除src/locale_impl.cpp文件第617行被#ifndef _STLP_NO_WCHAR_T包围的代码:

    new collate<wchar_t>(1),

    new ctype<wchar_t>(1),

ifndef _STLP_NO_MBSTATE_T

    new codecvt<wchar_t, char, mbstate_t>(1),

else

    0,

endif

    new moneypunct<wchar_t, true>(1),

    new moneypunct<wchar_t, false>(1),

    new numpunct<wchar_t>(1),

    new messages<wchar_t>(new _STLP_PRIV _Messages()),

    new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

    new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

    new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

    new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

    new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

    new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),

    0,

 

七.考虑fpic选项

32bit64bit下,可能会有不同的需求,因此,可以通过修改build/Makefiles/gmake/gcc.mak文件来控制编译选项。

 

八.部分模拟libsupc++

在某些特殊需要的情况下,可以不链接libstdc++库和libsupc++库。

8.1 build/lib/Makefile.inc文件中增加编译../../src/supc++.cpp

8.2 src目录下新建文件supc++.cpp,其内容如下:

#include <stdlib.h>

 

void* operator new(size_t size)

{

    void* p = malloc(size);

    return p;

}

 

void* operator new[](size_t size)

{

    void* p = malloc(size);

    return p;  

}

 

void operator delete(void* p)

{

    free(p);   

}

 

void  operator delete[](void* p)

{  

    free(p);  

}

 

extern "C"

void __cxa_pure_virtual()

{

    return;

}

 

九.移除typeid

如果使用了-fno-rtti编译选项,那将导致src/facets_byname.cpp文件编译错误,因为该文件中用到了typeid函数,恰巧的是,这是和locale相关的部分,因为我们不需要locale支持,所以,简单的删除typeid函数或者修改为一个printf以防万一即可。

 

十.其他函数

10.1 比如fstatfcntl等,由于某些限制,无法获取这些函数的支持,应该是和文件读写有关,那么只能是假设应用程序不用stl库进行文件操作。

10.2 在文件src/num_put_float.cpp中增加定义,主要用来处理一些浮点数相关函数。

#define USE_SPRINTF_INSTEAD

10.3 mktime函数,直接删除,改以printf进行输出监视。

 

 

经过以上修改后,最后得到的静态库中将只依赖c库函数和一些math库函数,除此,不再依赖其他函数库,可以解决某些情况下的某些问题。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值