rm -rf /usr/local/msvc64/* cd D:/build/pg tar -xf uuid-1.6.2.tar.gz cd uuid-1.6.2 #记得在configure前要先配置Windows和VC环境 #因源码问题VC上只能编译静态链接库 ./configure --host=x86_64-w64-mingw32 --prefix=/usr/local/msvc64 \ --enable-static=yes --enable-shared=no \ CC="$HOME/msvc/compile cl -nologo" \ CFLAGS="-MD" \ CXX="$HOME/msvc/compile cl -nologo" \ CXXFLAGS="-MD" \ CPPFLAGS="-D_WIN32_WINNT=$win32_target -I/usr/local/msvc64/include" \ LDFLAGS="-L/usr/local/msvc64/lib" \ LD="link" \ NM="dumpbin -symbols" \ STRIP=":" \ AR="$HOME/msvc/ar-lib lib" \ RANLIB=":" #configure后会根据系统环境自动生成头文件,需要重新设置权限,否则外部无法修改 chmod 777 *.h chmod 777 *.c
#if defined(_WIN32) && !defined(WIN32) #define WIN32 #endif #if defined(_WIN64) && !defined(WIN64) #define WIN64 #endif
#include <unistd.h> 修改为 #ifdef HAVE_UNISTD_H #include <unistd.h> #endif
#include <sys/time.h> 修改为 #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif
#if defined(WIN32) #define WINVER 0x0500 #include <windows.h> #include <wincrypt.h> #endif 修改为 #if defined(WIN32) #define WINVER 0x0500 #include <windows.h> #include <wincrypt.h> #include <process.h> #define ALREADY_HAVE_STRUCT_TIMEVAL 1 typedef unsigned int pid_t; #endif
#ifndef HAVE_STRUCT_TIMEVAL struct timeval { long tv_sec; long tv_usec; }; #endif 修改为 #ifndef HAVE_STRUCT_TIMEVAL #ifndef ALREADY_HAVE_STRUCT_TIMEVAL struct timeval { long tv_sec; long tv_usec; }; #endif #endif
make make install cd D:/build/pg rm -f /cygdrive/d/build/pg/uuid-1.6.2 cp /usr/local/msvc64/include/uuid.h /cygdrive/e/pgsql/include #编译PostgreSQL时引用的库名称为uuid.lib cp /usr/local/msvc64/lib/libuuid.lib /cygdrive/e/pgsql/lib/uuid.lib
make最后链接uuid_cli时会报链接错误,因为我们只需要静态库,不需要exe(uuid_cli会编译成exe),所以无需理会。
Microsoft (R) Library Manager Version 14.29.30137.0 Copyright (C) Microsoft Corporation. All rights reserved. libtool: link: ( cd ".libs" && rm -f "libuuid.la" && ln -s "../libuuid.la" "libuuid.la" ) /home/lxg/msvc/compile cl -nologo -I. -I. -D_WIN32_WINNT=_WIN32_WINNT_WIN8 -I/usr/local/msvc64/include -DHAVE_CONFIG_H -MD -c uuid_cli.c uuid_cli.c uuid_cli.c(112): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(112): warning C4047: “函数”:“const char *”与“int”的间接级别不同 uuid_cli.c(112): warning C4024: “strtol”: 形参和实参 1 的类型不同 uuid_cli.c(120): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(122): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(124): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(127): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(135): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(135): warning C4047: “函数”:“const char *”与“int”的间接级别不同 uuid_cli.c(135): warning C4024: “fopen”: 形参和实参 1 的类型不同 uuid_cli.c(142): error C2065: “optarg”: 未声明的标识符 uuid_cli.c(142): warning C4047: “函数”:“const char *”与“int”的间接级别不同 uuid_cli.c(142): warning C4024: “strtol”: 形参和实参 1 的类型不同 uuid_cli.c(159): error C2065: “optopt”: 未声明的标识符 uuid_cli.c(162): error C2065: “optind”: 未声明的标识符 uuid_cli.c(163): error C2065: “optind”: 未声明的标识符 make: *** [Makefile:103: uuid_cli.o] Error 2