Windows下编译安装Privoxy

首先,要安装MingW。在此不赘述。当然,用cygwin也可以,但是这样编译出来的Privoxy没有GUI图形界面。PS:Privoxy在jcc.c那里已经自动识别了MingW,并且嵌入了Windows GUI的API,因此编译出来就可以自己采用图形界面了。

然后,在这里下载Privoxy的源代码,本文以privoxy-3.0.18-stable为例。

进入privoxy-3.0.18-stable源码目录,执行以下命令,进入bash:

bash

执行以下命令,进行配置:

autoheader
autoconf
./configure --prefix=/r/privoxy --enable-mingw32 --disable-pthread

稍微解释以下configure的各个参数。--prefix参数指明privoxy的安装目录,/r/privoxy是mingw表示windows文件系统的方式,即R盘的privoxy文件夹。--enable-mingw32指明了为mingw环境配置,其实不指明配置程序也会自动检测得到。--disable-pthread是禁用POSIX的pthread,privoxy会自动使用windows API的thread来实现线程,具体参照errlog.c的部分代码:

/*********************************************************************
 *
 * Function    :  get_thread_id
 *
 * Description :  Returns a number that is different for each thread.
 *
 *                XXX: Should be moved elsewhere (miscutil.c?)
 *
 * Parameters  :  None
 *
 * Returns     :  thread_id
 *
 *********************************************************************/
static long get_thread_id(void)
{
   long this_thread = 1;  /* was: pthread_t this_thread;*/

#ifdef __OS2__
   PTIB     ptib;
   APIRET   ulrc; /* XXX: I have no clue what this does */
#endif /* __OS2__ */

   /* FIXME get current thread id */
#ifdef FEATURE_PTHREAD
   this_thread = (long)pthread_self();
#ifdef __MACH__
   /*
    * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
    * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
    * pthread_t is supposed to be opaque... but it's fairly random, though, so
    * we make it mostly presentable.
    */
   this_thread = abs(this_thread % 1000);
#endif /* def __MACH__ */
#elif defined(_WIN32)
   this_thread = GetCurrentThreadId();
#elif defined(__OS2__)
   ulrc = DosGetInfoBlocks(&ptib, NULL);
   if (ulrc == 0)
     this_thread = ptib -> tib_ptib2 -> tib2_ultid;
#endif /* def FEATURE_PTHREAD */

   return this_thread;
}

配置成功后,编译安装:

make

make install

其实,make后已经有privoxy.exe,可以下载官方的Win32版本的ZIP包,替换里面的privoxy.exe即可使用,无需再make install。

 

一些注意的问题:

1、编译时提示未定义“NI_MAXSERV”

编译时出现如下错误:

jbsockets.c: In function 'get_host_information':

jbsockets.c:979:22: error: 'NI_MAXSERV' undeclared (first use in this function)

jbsockets.c:979:22: note: each undeclared identifier is reported only once for e

ach function it appears in

make: *** [jbsockets.o] Error 1

修改jbsockets.c,在

const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;

前面加上:

/* MOD BY Creke START */

#ifndef NI_MAXSERV

#define NI_MAXSERV    32

#endif

/* MOD BY Creke END */

说实话,这是configure没有识别getnameinfo和getaddrinfo,因此config.h中没有定义HAVE_RFC2553所致。这些依赖于官方修复,再次仅拷贝ws2tcpip.h中的相关值进来,作临时修补。

2、MingW默认安装的话,需要额外的库吗?

需要zlib库,在mingw中又称为libz,可以在这里下载。当然,如果需要将privoxy拷贝到其它电脑运行,需要将libz-1.dll拷贝到privoxy程序目录中。

3、额外的DLL?

libgcc_s_dw2-1.dll

4、编译好如何发行和安装?

推荐下载官方发行的win32的zip包,将编译好的privoxy.exe覆盖。同时别忘记拷贝依赖的dll。

15 comments

  1. VILIC says:

    博主你好... 我没用过MinGW, 今天折腾了一晚上, 还是折腾不出来, 一个是libz, 可能我放的位置有问题, 提示no zlib found, 一个是make的时候, 提示unrecognized command line option -mno-cygwin. 不知道该怎么解决. 而且我在装好MinGW之后, 用开始菜单中的MinGW Shell(貌似是启动了msys/1.0/里的), 都没有autoconf什么的, 所以后来把根目录里的bin考进去才能用. 不知道怎么回事... 求help!

    1. creke says:

      这是MingW的安装或者配置问题,建议先参考官方文档安装配置好

  2. 康叔 says:

    你昨天在搜狗代理那篇博文说的做了一个Privoxy是不是这么做的啊。实现了什么啊?

    1. creke says:

      是这么编译的,加上了搜狗代理,呵呵

  3. 康叔 says:

    我就想问问你这么做实现了什么功能。他放出的不是也是http代理么。

    1. creke says:

      是啊,也是一样的功能啊

  4. 小铱 says:

    楼主好,
    我也是用的mingw编译的,不支持ipv6。不知道楼主编译的行不行。
    在xiaoxia那边看到过你,今天Google的时候又看见了

    1. creke says:

      我的网络没有IPV6接入,所以我测试不了,呵呵。你可以看一下编译config有没有ipv6或者ipv6的那段代码有没有被编译。

  5. 小铱 says:

    又来问下楼主,你gcc的版本是多少啊。我用其他版本不能make

    1. creke says:

      4.5.2,MingW的

    2. 小铱 says:

      楼主确定吗?我也会提示unrecognized command line option -mno-cygwin而无法编译。而且Google来看GCC在GCC 4版本里去除了这个参数

    3. creke says:

      有我在,没意外。当然确定。
      你的是最新版源码?那可能在windows编译有问题哦

    4. 小铱 says:

      privoxy3.0.19源码,自己改过。gcc4.6,从sf下的msys直接解压的。
      提示unrecognized command line option -mno-cygwin

    5. creke says:

      config的问题,也可能是新版源码的问题

    6. 小铱 says:

      在configure.in里面去掉-mno-cygwin就和以前一样了,多谢。另外不知道楼主把sogou的验证加在哪里了,回头写个帖子吧,交流一下。

Leave a Reply to 小铱 Cancel reply