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''



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