ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Windows编译ossp-uuid

2021-12-07 12:32:27  阅读:280  来源: 互联网

标签:cli 未声明 Windows C2065 ossp error include uuid


  • 操作系统版本Windows 11 X64专业版
  • Visual Studio 2019 Professional
  • Cygwin64安装gcc-core、g++、gdb、make、libtool包
  • 以下所有命令均在“Cygwin64 Terminal”命令行中执行
  • 网上可以下载别人修改好的Visual Studio工程直接编译,但是版本比较老,因此我们下载最新版的编译。
  • ossp-uuid在windows中使用动态库必须在函数前声明dllexport或者定义.def文件,但源码中未定义,同时我们仅对源码小幅修改,因此在Windows上只能编译为静态链接库。
  • 本节需要在Cygwin中执行,在执行之前必须配置Windows和VC环境,请参看在Windows上通过cygwin和VC编译64位iconv库.

1 配置环境

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

2 修改文件config.h,在文件最后添加WINDOWS定义

#if defined(_WIN32) && !defined(WIN32)
#define WIN32
#endif

#if defined(_WIN64) && !defined(WIN64)
#define WIN64
#endif

3 修改文件uuid.h、uuid_ac.h、uuid.c、uuid_mac.c、uuid_prng.c、uuid_time.c、uuid_cli.c

#include <unistd.h>
修改为
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

4 修改文件uuid.c、uuid_mac.c、uuid_prng.c、uuid_time.c

#include <sys/time.h>
修改为
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif

5 修改文件uuid_prng.c,在#include <wincrypt.h>下增加以下内容

#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

6 修改文件uuid_time.h

#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

7 开始编译

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

标签:cli,未声明,Windows,C2065,ossp,error,include,uuid
来源: https://blog.csdn.net/kmblack1/article/details/121766014

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有