windows下使用boost编译levelBD小记。

使用boost编译leveldb的好处是xp下能用,本博客上一篇文章编译出来的因为不是使用google官方代码,编译出来不支持xp。

本次使用官方源,windows分支,xp运行通过。


一)。下载boost :

http://iweb.dl.sourceforge.net/project/boost/boost/1.52.0/boost_1_52_0.tar.bz2

50多M,解压后先运行一个bootstrap.bat, 再按提示运行b2.exe, 不想全编译的可以看b2.exe的帮助

bootstrap.bat

D:\src\boost_1_52_0>bjam install --toolset=msvc-9.0 link=static runtime-link=static threading=multi release address-model=32 --with-date_time --with-filesystem --with-thread --with-chrono 


我I5上,编译了20分钟左右。

以上命令是编译并安装好,默认安装目录是 C:\Boost

threading=multi 是必需的,好像默认使用单线程,vs不能链接过。

msvc-9.0是使用vs2008编译, 注意把vs2008的tools目录加到环境变量中。


然后再按提示把相关头文件目录与静态库目录加到vs中:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    C:\Boost\include\boost-1_52

The following directory should be added to linker library paths:

    C:\Boost\lib


二)然后 就是去levelDB下载 源码,具体的编译流程,官网的windows分支有说明:

https://code.google.com/p/leveldb/source/browse/WINDOWS?name=windows

下载选择windows分支,一开始没留意到这个分支选择,下载了几次都没有port_win.h等相关文件,

此分支主要是有以下几个文件:

port/port_win.h
port/port_win.cc
util/env_boost.h
util/win_logger.cc
util/win_logger.h

然后 修改port/port.h文件。这步是上面那个说明没提到的:

// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#ifndef STORAGE_LEVELDB_PORT_PORT_H_
#define STORAGE_LEVELDB_PORT_PORT_H_

#include <string.h>

// Include the appropriate platform specific file below.  If you are
// porting to a new platform, see "port_example.h" for documentation
// of what the new port_<platform>.h file must provide.
#if defined(LEVELDB_PLATFORM_POSIX)
#  include "port/port_posix.h"
#elif defined(LEVELDB_PLATFORM_CHROMIUM)
#  include "port/port_chromium.h"
#elif defined(LEVELDB_PLATFORM_ANDROID)
#  include "port/port_android.h"
#elif defined(LEVELDB_PLATFORM_WINDOWS)  // 主要添加此宏与
#  include "port/port_win.h"   // 幷包含此头文件
#endif#endif // STORAGE_LEVELDB_PORT_PORT_H_

最后比较重要的一步,把port/win/stdint.h文件删除 或改名。

原因在:http://www.ogre3d.org/forums/viewtopic.php?f=2&t=70414 拉到最后看发帖者的回答。

其实就boost包含stdin.h文件,而工程中又有一个同名的,被先包含了,造成以下错:

1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(104): error C2039: 'int_least8_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(104): error C2873: 'int_least8_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(105): error C2039: 'int_fast8_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(105): error C2873: 'int_fast8_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(107): error C2039: 'uint_least8_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(107): error C2873: 'uint_least8_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(108): error C2039: 'uint_fast8_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(108): error C2873: 'uint_fast8_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(111): error C2039: 'int_least16_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(111): error C2873: 'int_least16_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(112): error C2039: 'int_fast16_t' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(112): error C2873: 'int_fast16_t' : symbol cannot be used in a using-declaration
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\boost_1_52_0\boost/cstdint.hpp(114): error C2039: 'uint_least16_t' : is not a member of '`global namespace''



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章