下蝲openvpn最新版本,目前E_版本是openvpn-2.0.9 http://openvpn.net/
我的机器环境?vc6.0 + vc2003 platform_sdk
下蝲以后解压Qmain函数在openvpn.c文g中,vc6打开q文Ӟ其?.h *.c文g全部加入到工E中Q编译运行,报一大堆?
include\winsock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition
include\winsock2.h(144) : warning C4005: 'FD_SET' : macro redefinition
include\winsock.h(88) : see previous definition of 'FD_SET'
include\winsock2.h(153) : error C2011: 'timeval' : 'struct' type redefinition
include\winsock2.h(209) : error C2011: 'hostent' : 'struct' type redefinition
include\winsock2.h(222) : error C2011: 'netent' : 'struct' type redefinition
include\winsock2.h(229) : error C2011: 'servent' : 'struct' type redefinition
include\winsock2.h(241) : error C2011: 'protoent' : 'struct' type redefinition
include\winsock2.h(397) : error C2011: 'sockaddr_in' : 'struct' type redefinition
include\winsock2.h(407) : error C2011: 'WSAData' : 'struct' type redefinition
.................................
q是׃<config-win32.h>文g中包含了
#include <windows.h>
#include <winsock2.h>
windows.h中又包含?lt;winsock.h>D和winsock2.h冲突Q解x法是在include<windows.h>之前d?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
因ؓ用到了winsock2.h 所以必d入lib文g:ws2_32.lib
再次~译Q出现如下错?
mudp.c
this compiler appears to lack vararg macros which will cause a significant degradation in efficiency
e:\libtools\openvpn-2.0.9\lzo.h(32) : fatal error C1083: Cannot open include file: 'lzo1x.h': No such file or directory
multi.c
this compiler appears to lack vararg macros which will cause a significant degradation in efficiency
e:\libtools\openvpn-2.0.9\lzo.h(32) : fatal error C1083: Cannot open include file: 'lzo1x.h': No such file or directory
ntlm.c
this compiler appears to lack vararg macros which will cause a significant degradation in efficiency
occ.c
this compiler appears to lack vararg macros which will cause a significant degradation in efficiency
e:\libtools\openvpn-2.0.9\lzo.h(32) : fatal error C1083: Cannot open include file: 'lzo1x.h': No such file or directory
openvpn.c
#ifdef USE_LZO
#ifdef LZO_HEADER_DIR
#include "lzo/lzoutil.h"
#include "lzo/lzo1x.h"
#else
#include "lzoutil.h"
#include "lzo1x.h"
#endif
因ؓopenvpn默认配置用到了lzo压羃库,所以下载lzo压羃?lzo-2.03,q且lzo-2.03包中的include文g加入到工E中Q注意文件目录层ơ,我是额外定义了lzo文g夹,头文g全部加入q去的,因此必须加上~译选项:LZO_HEADER_DIR
另额外编译lzo lib:
lzo解压至C盘根目录Q在命o行中跌该目录,q行b\win32\mc120.batQ编译成功后生成lzo.lib
生成的lzo.libd到工E中?br>另如果不是用lzo可以修改<config_win32.h>头文? (openssl ssl crypto也可以不使用Q视具体情况)
/* Use OpenSSL crypto library */
#define USE_CRYPTO 1
/* Use LZO compression library */
#define USE_LZO 1
/* Use OpenSSL SSL library */
#define USE_SSL 1
/* Version number of package */
#define VERSION PACKAGE_VERSION
接着如果使用OpenSSLQ那么首先要下蝲OpenSSL库,然后~译:
a.OpenSSL解压到C盘根目录下;
b.在命令提C中进入该目录Q输入perl Configure VC-WIN32Q检验perl是否正确安装Q?br> c.命o行中输入ms\do_msQ?br> d.命o行中转到Microsoft Visual Studio\VC98\binQ运行vcvars32.bat以配|环境变量?br> e.命o行OpenSSL目录下,执行nmake –f ms\ntdll.mak ~译成功后,在out32dll目录下,会有四个文glibeay32.dll libeay32.lib ssleay32.dll?ssleay32.lib,编译成功的lzo.lib libeay32.lib ssleay32.libd到工E中Qƈlibeay32.dll ssleay32.dll拯到Debug目录?q且加入openssl的头文g到工E中Q和lzo库类似的q程?br>
另外因ؓVC中不识别unsigned long long intcdQ需改ؓ_int64。修?lt;common.h>头文?
#ifdef USE_64_BIT_COUNTERS
// typedef unsigned long long int counter_type;
typedef _int64 counter_type; //qj modify
# ifdef WIN32
# define counter_format "%I64u"
# else
# define counter_format "%llu"
# endif
#else
typedef unsigned int counter_type;
# define counter_format "%u"
#endif
再次~译Q发现错误少多了Q而且全部只是一些link错误?
Linking
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
cryptoapi.obj : error LNK2001: unresolved external symbol __imp__CertFreeCertificateContext@4
cryptoapi.obj : error LNK2001: unresolved external symbol __imp__CryptAcquireCertificatePrivateKey@24
cryptoapi.obj : error LNK2001: unresolved external symbol __imp__CertCloseStore@8
cryptoapi.obj : error LNK2001: unresolved external symbol __imp__CertOpenStore@20
cryptoapi.obj : error LNK2001: unresolved external symbol __imp__CertFindCertificateInStore@24
route.obj : error LNK2001: unresolved external symbol _GetIpForwardTable@12
route.obj : error LNK2001: unresolved external symbol _CreateIpForwardEntry@4
route.obj : error LNK2001: unresolved external symbol _DeleteIpForwardEntry@4
tun.obj : error LNK2001: unresolved external symbol _GetAdaptersInfo@8
tun.obj : error LNK2001: unresolved external symbol _IpReleaseAddress@4
tun.obj : error LNK2001: unresolved external symbol _GetInterfaceInfo@8
tun.obj : error LNK2001: unresolved external symbol _IpRenewAddress@4
tun.obj : error LNK2001: unresolved external symbol _AddIPAddress@20
tun.obj : error LNK2001: unresolved external symbol _FlushIpNetTable@4
tun.obj : error LNK2001: unresolved external symbol _DeleteIPAddress@4
tun.obj : error LNK2001: unresolved external symbol _GetAdapterIndex@8
Debug/openvpn.exe : fatal error LNK1120: 16 unresolved externals
Error executing link.exe.
openvpn.exe - 17 error(s), 1 warning(s)
首先解决crytoapi.obj的lnk错误Q找到crytoapi.c文g中的CertFreeCertificateContext
函数Q找到其声明:WinCrypt.h文gQ?br>
#include <wincrypt.h> //需要装PLATFORM SDK
#pragma comment (lib, "crypt32.lib")
然后解决route.obj tun.obj的问题,也是通过route.c文g中的 GetIpForwardTable{其中一个link错误的函敎ͼ扑ֈ其声明文?IPHlpApi.h
#include <iphlpapi.h>
#pragma comment (lib, "iphlpapi.lib")
最后再ơ编译,OKQ开始你的openvpn代码调试吧!Q!

]]>