如何使用VS2005编译
这篇文章帮助你用用Microsoft C++编译器编译OpenWenGo
需求:
VS2005 Express
Platform SDK
DirectX SDK
其他WengoPhone的依赖软件:Python,Scons,Qt,Boost
XP Sp2补丁
C:空间大于 4G
D:空间足够多
Microsoft 开发工具和SDK的安装
VS2005默认安装在C: (我的装在D:)
Platform SDK
VS2005不包括编译所需的头文件和库文件.这些文件包含在Platform SDK 中. Platform SDK可以在这里下载here.
把Platform SDK安装在D:/Program Files/Platform SDK,编辑vs32var.bat脚本文件(位于FIXME中),将以下路径加入系统路径变量中(INCLUDE):
- D:/Program Files/Platform SDK/include
- D:/Program Files/Platform SDK/include/atl
LIB:
· D:/Program Files/Platform SDK/lib
Platform SDK 不包括DirectX的头文件和库文件.它们包含在DSK中. DirectX SDK可以在这里下载here.你可以将其安装在D:/ProguamFiles/DirectX SDK
编辑vs32var.bat脚本文件(位于FIXME中)
加入定义头文件的路径:
· D:/Program Files/DirectX SDK/include;
LIB:
- D:/Program Files/DirectX SDK/lib;
此外,你可以编辑setenv.bat脚本文件假如以上路径,详细请参考附录
编译工具(Build tools)
下载Python 2.4.3 à here.
下载Python对Windows的扩展à here(不要改变安装路径)
下载Scons0.96à here.
编辑PATH环境变量把scons.bat文件包含其中,这个文件在Python的安装目录.
需要的库:
QT
下载QT 4.1.2 à from trolltech.
解压到:D:/QT/ 4.1.2
下载QT作为vs2005的补丁this patch
应用补丁:在QT的目录解压acs 4qt 412p1.zip
进入QT的目录运行installpatch41.bat
运行"qconfigure.bat msvc2005".此时将创建makefile并且编译整个QT库.
加入PATH环境变量: C:/Qt/ 4.1.2 /bin;C:/Program Files/Python24
创建环境变量QTDIR=D:/QT/ 4.1.2 .
Boost
下载Boostà here.
下载jamà here.
运行boost_1_33_1.exe抽取原文件到D:/boost_1_33_1目录
解压缩boost-jam- 3.1.13 -1-ntx86.zip 再把bjam.exe复制到D:/boost_1_33_1
转到Boost的原文件目录运行
· bjam "-sTOOLS=vc-8_0" “—prefix=d:/” install
设置环境变量
安装WengoPhone
检查源代码文件(略)
改写Boost的库名
请使用以下步骤:
编辑wengoscons/lib/boost/Sconscript 将库名字由boost-xx-vc71-* 改为 boost-xx-vc80-*:
· if WengoCCMSVC():
· libs += [
· 'libboost_thread-vc80-mt.lib',
· 'libboost_serialization-vc80-mt.lib',
· 'libboost_signals-vc80-mt.lib',
· 'libboost_regex-vc80-mt.lib',
· 'libboost_program_options-vc80-mt.lib',
· ]
出现的错误:在编译DLL时找不到Boost库
说明: Boost库名包含着编译器的版本信息,当使用VS2005编译Boost时,原来的VC71已经被VC80所代替.
首先(First workaround):首先构件libcurl再编辑它的脚本文件(SConscript)
方法:
打开VS2005的命令模式
· > d:/
· > cd /wengophone
· > scons mode=release-symbols owcurl
· 编译成功后,编辑libs/curl/Sconscript将Include_path = [ ‘include’, ‘lib’ ] 改为Include_path = [ ‘include’ ]
出现的错误:在编译main.cpp时xiobase的头文件_SH_DENYNO未定义
说明:share.h包含在libs/curl/lib中,正好和编译main.cpp时的内建文件share.h冲突.
其次(Second workaround:):从netlib.cpp中删除多余的声明
方法:
编辑wifo/netlib/src/netlib.cpp
删除或者注释掉以下声明(它们已经在wininet.h中有定义).
· typedef struct {
· BOOL(* IsResolvable) (LPSTR lpszHost);
· DWORD(* GetIPAddress) (LPSTR lpszIPAddress, LPDWORD lpdwIPAddressSize);
· BOOL(* ResolveHostName) (LPSTR lpszHostName, LPSTR lpszIPAddress, LPDWORD lpdwIPAddressSize);
· void(* IsInNet) (LPSTR lpszIPAddress, LPSTR lpszDest, LPSTR lpszMask);
· } AutoProxyHelperVtbl;
·
· typedef struct {
· AutoProxyHelperVtbl * lpVtbl;
· } AutoProxyHelperFunctions;
·
· typedef struct {
· DWORD dwStructSize;
· LPSTR lpszScriptBuffer;
· DWORD dwScriptBufferSize;
· } AUTO_PROXY_SCRIPT_BUFFER;
·
· typedef BOOL(CALLBACK * pfnInternetInitializeAutoProxyDll) (
· DWORD dwVersion,
· LPSTR lpszDownloadedTempFile,
· LPSTR lpszMime,
· AutoProxyHelperFunctions * lpAutoProxyCallbacks,
· AUTO_PROXY_SCRIPT_BUFFER * lpAutoProxyScriptBuffer);
·
· typedef BOOL(CALLBACK * pfnInternetDeInitializeAutoProxyDll) (
· LPSTR lpszMime,
· DWORD dwReserved);
·
· typedef BOOL(CALLBACK * pfnInternetGetProxyInfo) (
· LPCSTR lpszUrl,
· DWORD dwUrlLength,
· LPSTR lpszUrlHostName,
· DWORD dwUrlHostNameLength,
· LPSTR * lplpszProxyHostName,
· LPDWORD lpdwProxyHostNameLength);
·
· #define PROXY_AUTO_DETECT_TYPE_DNS_A 2
· #define PROXY_AUTO_DETECT_TYPE_DHCP 1
出现的错误:编译错误,用不同的类型对某些功能2次定义
说明:我认为VS2003的wininet.h不包含所需求的声明,这些声明已经存在.
第三(Third workaround):在链接PhApi是找不到atlthunk.lib库
missing lib atlthunk.lib when linking PhApi
编辑D:/Program Files/Platform SDK/include/atl/atlbase.h
注释掉以下信息
· /*
· PVOID __stdcall __AllocStdCallThunk(VOID);
· VOID __stdcall __FreeStdCallThunk(PVOID);
·
· #define AllocStdCallThunk() __AllocStdCallThunk()
· #define FreeStdCallThunk(p) __FreeStdCallThunk(p)
·
· #pragma comment(lib, "atlthunk.lib")
· */
添加以下定义用来替换:
· // workaround for not having atlthunk.lib in PSDK or VC++ 2005 Express Edition
· #define AllocStdCallThunk() HeapAlloc(GetProcessHeap(),0,sizeof(_stdcallthunk))
· #define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)
如果你忘记了这一步将会遇到错误,在重新编译前不要忘记删除预编译头文件vc80.pch(在ow目录中).
出现的错误:编译PhApi.dll时连接错误,找不到atlthunk.lib
说明:atlthunk.lib仅包含在完全安装的VS2005zhong ,但是如果ATL类没有用与工作环境中,将能够正确编译和连接.
更详细的信息参见:
- http://forums.microsoft.com/msdn/showpost.aspx?postid=64509&siteid=1
- http://resources.kairo.at/mozilla/build/make-win-tinderbox-vc8express.html
第四(Fourth workaround):纠正DirectXWebCam头文件
方法:
· 在#include <dshow.h>之前添加#include <tchar.h>
DirectXWebCamDriver.h and DirectXWebCamUtils.h.
两个文件都要改
出现的错误:在echar.h后要包含strsafe.h
说明:MSDN论坛上有一些含糊的说明here.
有两个常见的问题:1)编译unicode和ansi或者vice versa过滤器2)在VS2005已经将Treat wchar_t作为一个内建的数据类型.一定要让这个设置与你的过滤器和基础类库一致.注意:命令模式和图形模式表现出的错误是不同的.
第五(Fifth workaround: GAIM IM Factory)
编辑Fifth workaround: GAIM IM Factory libs/imwrapper/src/gaim/GaimIMFactory.cpp
注释掉glib的头文件包含
- Edit libs/imwrapper/src/gaim/GaimIMFactory.cpp
- Comment out extern “C” directive around glib includes:
· // extern “C” {
· #include "glib.h"
· #include "gaim/internal.h"
· #include "gaim/core.h"
· #include "gaim/eventloop.h"
· #include "gaim/blist.h"
· #include "gaim/util.h"
· #include "gaim/connection.h"
· #include "gaim/blist.h"
· #include "gaim/conversation.h"
· #include "gaim/account.h"
· #include "gaim/privacy.h"
·
· // }
出现的问题:D:/Program Files/Microsoft Platform SDK/Include/wspiapi.h(44) : error C2894: templates cannot be declared to have 'C' linkage
说明:Glib头文件包含了一些使用模版的系统头文件,但是外部变量"c"在cplusplus中的定义没有删除. Glib头文件好象已经包含了外部变量"c"
第六(AvatarList? header file order):头文件的顺序
编辑Sixth workaround: AvatarList? header file order
删除#include "AvatarList?.h"中的以下信息
· * You should have received a copy of the GNU General Public License
· * along with this program; if not, write to the Free Software
· * Foundation, Inc., 59 Temple Place, Suite 330 , Boston , MA 02111-1307 USA
· */
·
·
· #include <model/config/Config.h>
· #include <model/config/ConfigManager.h>
·
· #include <util/File.h>
· #include <util/Path.h>
·
· #include "AvatarList.h" // won't compile in vc++ 2005 unless moved down
·
· AvatarList::AvatarList() {
· }
出现的错误: C:/Programmi/Microsoft Visual Studio 8/VC/INCLUDE/swprintf.inl(41) :error C2664: '_vswprintf_c_l' : cannot convert parameter 4 from 'void *' to '_locale_t' Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Win32dep.h中名字的矫正
方法:
编辑: libs/gaim/include/gaim/win32dep.h.
- Surround function declarations with:
· #ifdef __cplusplus
· extern "C" {
· #endif
·
· (…)
· Functions declarations
· (…)
·
· #ifdef __cplusplus
· }
· #endif
出现的错误:在创建qtwengophone.lib时外部变量wgain_init没有定义
说明:预编译的libgaim已经是一个c的库了
复制库文件(and wchar_t problems)
在最后连接wengophoneng.exe时如果你遇到了连接错误fatal error LNK1169: or more multiply defined symbols found,你应该修改wengophone.py(主scons的编译脚本,在/wengoscons/wengoscons中)
第500行,正确的是:
class CCMSVC:
"""
MSVC (Microsoft Visual C++) compiler support.
"""
def setReleaseModeWithSymbols(self):
self.__setDefaultFlags()
self.__CCFlags += ['/O1', '/MD', '/Zi']
self.__linkFlags += ['/DEBUG', '/NODEFAULTLIB:MSVCRTD.LIB',
'/NODEFAULTLIB:libcpmt.lib']
def __setDefaultFlags(self):
self.__CCFlags = ['/Zm200', '/EHsc', '/GR']
self.__linkFlags = []
主要的修改是self.linkFlags and self.CCFlags
[本说明文档应该做为测试版]
在连接时,你可能遇到更多的和wchar_t有关的错误,以下将帮你解决.
你可能遇到以上提到的和wchar_t有关的问题.试着修改wengophone.py如下(相似)
def __setDefaultFlags(self):
#old line msvc self.__CCFlags = ['/Zm200', '/EHsc', '/GX', '/GR']
self.__CCFlags = ['/Zm200', '/EHsc', '/GR', '/Zc:wchar_t'] # new line
self.__linkFlags = []
这可能导致另一个错误:
webcam.lib(DirectXWebcamDriver.obj) : error LNK2019: unresolved external symbol
"char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)"
为了解决这个问题你应该编辑wifo/phapi/Sconscript so that the occurrence of comsupp becomes comsuppw(据邮件列表中所说这个改变应该在webcam目录,因此是可选的)
if WengoCCMSVC():
libs += [
'comsuppw',
]
编辑(Compilation)
如何开始:
· Open:
Start All programs Visual C++ 2005 Express Edition Visual Studio 2005 Command prompt
· Launch: scons mode=release-symbols qtwengophone
· Or modify the project file attached below
Other targets (these may or may not work, but it's a starting point)
· Launch: scons mode=release-symbols qtwengophone-translations
· Launch: scons mode=release-symbols qtwengophone-nsis-installer-without-pdb
运行WengoPhone NG
Manifest file
从VS2005启动, Manifest file (manifest files have been introduced to circumvent the DLL hell problem),你必须从你的编译目录复制到它的跟目录,否则WengoPhone 将不能加载mscvr80.dll
附录:环境变量
BOOSTINCLUDEDIR=d:/boost/include/boost-1_33_1
BOOSTLIBDIR=D:/boost/lib
FrameworkSDKDir=C:/Program Files/Microsoft Visual Studio 8/SDK/v2.0
FrameworkVersion=v2.0.50727
INCLUDE=D:/Program Files/Microsoft Platform SDK/Include/atl;D:/Program Files/DirectX SDK/Include;D:/Program Files/Microsoft Platform SDK/Include;C:/Program Files/Microsoft Visual Studio 8/VC/INCLUDE;
LIBPATH=C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727
Path=D:/Program Files/Microsoft Platform SDK/Bin;C:/Program Files/Microsoft Visual Studio 8/Common7/IDE;C:/Program Files/Microsoft Visual Studio 8/VC/BIN;C:/Program Files/Microsoft Visual Studio 8/Common7/Tools;C:/Program Files/Microsoft Visual Studio 8/SDK/v2.0/bin;C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727;C:/Program Files/Microsoft Visual Studio 8/VC/VCPackages;D:/Program Files/DirectX SDK/Utilities/Bin/x86";C:/WINDOWS/system32;C:/WINDOWS;d:/Python24
QTDIR=D:/Qt/
4.1.2
QTJAVA=C:/Program Files/QuickTime/QTSystem/QTJava.zip
VCINSTALLDIR=C:/Program Files/Microsoft Visual Studio 8/VC
VS80COMNTOOLS=C:/Program Files/Microsoft Visual Studio 8/Common7/Tools/
VSINSTALLDIR=C:/Program Files/Microsoft Visual Studio 8
以工程文件作为启动点
Attached is a project file that can be used as a starting point for building wengophone integrated into VS2005. It will need to be modified so that all directories point to where you have put the files.
Specifically (but not guaranteed to be all the spots) you will have to point to the proper directories:
Project->Properties->Configuration Properties->NMake->General->Build Command Line:
Project->Properties->Configuration Properties->NMake->General->Rebuild All Command Line:
Project->Properties->Configuration Properties->Debugging->Environment: You may want to remove the debugging flags here.
Tools->Options->Projects and Solutions->VC++ Directories->Win32->Include files: Add the following:
C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Include
C:/Program Files/Microsoft DirectX SDK/Include
Tools->Options->Projects and Solutions->VC++ Directories->Win32->Library files: Add the following:
C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Lib
interesting ML threads ¶
* http://thread.gmane.org/gmane.comp.voip.wengophone.devel/3150/focus=3150
Attachments
- VCCWengo.vcproj (360.9 kB) -This will need to be modified for your environment., added by lukaso on 12/18/06 20:28:01.
编译boost库-用vc2005编译boost
1.33.1
//打开控制台窗口,请使用vs2005在开始菜单中的“Visual Studio Tools->Visual Studio 2005 命令提示”打开控制台,这样vc的的编译环境就设置好了。
//假设boost安装包的解压的目录为{BOOST_SRC}中。
//先编译出bjam.exe,它被用于安装boost库
cd {BOOST_SRC}/tools/build/jam_src
build.bat
//利用编译出的bjam.exe程序编译并安装boost库
cd {BOOST_SRC}
copy {BOOST_SRC}/tools/build/jam_src/bin.ntx86/bjam.exe
//下面的命令的各选项的说明:
//prefix 将boost安装到的路径(生成的头文件和库文件都会放到该路径中)。
//重定义以下变量(利用-s设置):
//VC80_ROOT vc2005的安装路径,如果未将vc2005安装到默认位置,你必须指定该项。
//TOOLS 使用的编译工具,vc2005对应的是vc-8_0
//PYTHON_ROOT python的安装目录,如果未将BOOST安装到默认位置,你必须指定该项。
//BUILD 编译结果选项,默认会生成尽可能多的版本,如调试版/发行版,静态库/动态库,单线程/多线程。
bjam "-sVC80_ROOT=D:/Program Files/Microsoft Visual Studio 8/VC" "-sTOOLS=vc-8_0" "-sPYTHON_ROOT=D:/Program Files/Python24" "--prefix=E:/librarys/boost" install
boost在vc2005中的编译出现codepage警告和DEPRECATED函数的解决近日下载了一个VC2005 Express Edition,用它来编译boost,发现有不少的warning C4819,说代码文件中有cp936无法表示的字符,还有就是vc2005特有的废弃的ANSI函数的错误,虽说不影响编译,但是看着时不时出现的warning总是让人心神不安,还容易掩盖其他的错误,如果是直接用cl编译,只要加上/wd4819 /D_CRT_SECURE_NO_DEPRECATE就可以不显示这两个错误,但是大家都知道boost是使用其特有的boost.build进行编译的,下面我就给出如何修改boost.build来抑制这两个错误的显示
boost.build分为v1和v2两个版本
v1:
修改$(BOOST_ROOT)/tools/build/v1/vc-8_0-tools.jam
将
flags vc - 8_
0 C
++ FLAGS : / Zc:forScope ;
改为
flags vc - 8_
0 C
++ FLAGS : / Zc:forScope / wd4819 / D_CRT_SECURE_NO_DEPRECATE ;
v2:
cvs版本
修改$(BOOST_ROOT)/tools/build/v2/tools/msvc.jam
在
# 8.0 adds some more options
一行的下方加上
flags msvc.compile CFLAGS $(condition) : / wd4819 / D_CRT_SECURE_NO_DEPRECATE ;
boost
1.33.1
版本
将
# 8.0 deprecates some of the options
if ! [ MATCH ^ ([ 67 ]. * ) : $(version) ]
{
flags msvc.compile CFLAGS $(condition) /< optimization > speed : / O2 ;
flags msvc.compile CFLAGS $(condition) /< optimization > space : / O1 ;
flags msvc.link.dll MANIFEST : " mt -manifest " ;
flags msvc.link.dll OUTPUTRESOURCE : " -outputresource: " ;
}
改为:
# 8.0 deprecates some of the options
if ! [ MATCH ^ ([ 67 ]. * ) : $(version) ]
{
flags msvc.compile CFLAGS $(condition) : / wd4819 / D_CRT_SECURE_NO_DEPRECATE ;
flags msvc.compile CFLAGS $(condition) /< optimization > speed : / O2 ;
flags msvc.compile CFLAGS $(condition) /< optimization > space : / O1 ;
flags msvc.link.dll MANIFEST : " mt -manifest " ;
flags msvc.link.dll OUTPUTRESOURCE : " -outputresource: " ;