基于TDengine-ver-1.6.4.4在windows 10下cmake+msys2编译(windows cgo 使用)

背景

TDengine 提供的 go 连接器使用的是 cgo 且只能在 liunx 系统下使用,windows上的动态库是由vc编译器编译而成,cgo 无法使用,本文提供 windows 下用 gcc 编译器编译 TDengine 的步骤和本人编译后的成品。

重中之重!交叉编译后的动态库并不保证质量!生产环境 慎用!慎用!慎用!生产环境使用官方提供的 taos.dll 改名为 libtaos.dll 使用

下载地址

不想看编译步骤只想 下载使用 请点这里跳转到 github 下载 release

仓库地址

***

安装部署 msys2

安装

https://mirror.tuna.tsinghua.edu.cn/help/msys2/

安装完后打开 c:\msys64\msys2_shell.cmd 在窗口上右击, 选择 Options ,更改字符集 zh_cn gbk

修改 pacman 配置见上面网页 (有梯子可以省略这步)

修改后执行

pacman -S mingw-w64-x86_64-gcc
pacman -S make

配置环境变量

C:\msys64\mingw64\bin

C:\msys64\usr\bin


按以上顺序添加到系统变量 path

安装cmake:

https://cmake.org/download/

默认安装

下载 TDengine

https://github.com/taosdata/TDengine/archive/ver-1.6.4.4.zip

修改说明

CMakeLists.txt

注释或删除以下行:

    SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
SET(DEBUG_FLAGS "/Zi /W3 /GL")
SET(RELEASE_FLAGS "/W0 /GL")

src/client/CMakeLists.txt

注释或删除以下行:

SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def)

deps/iconv/iconv.c

修改以下行

const struct alias *
aliases2_lookup (register const char *str)
{
const struct alias * ptr;
unsigned int count;
for (ptr = sysdep_aliases, count = sizeof(sysdep_aliases)/sizeof(sysdep_aliases[0]); count > 0; ptr++, count--)
if (!strcmp(str, stringpool2 + ptr->name))
return ptr;
return NULL;
}

改为

// gcc -o0 bug fix
// see http://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=blobdiff;f=lib/iconv.c;h=31853a7f1c47871221189dbf597473a16d8a8da7;hp=5a1a32597fa3efc5f69624d37a2eb96f308cd241;hb=b29089d8b43abc8fba073da7e6dccaeba56b2b70;hpb=0a04404c90d6a725b8b6bbcd65e10c5fcf5993e9 static const struct alias *
aliases2_lookup (register const char *str)
{
const struct alias * ptr;
unsigned int count;
for (ptr = sysdep_aliases, count = sizeof(sysdep_aliases)/sizeof(sysdep_aliases[0]); count > 0; ptr++, count--)
if (!strcmp(str, stringpool2 + ptr->name))
return ptr;
return NULL;
}

os/windows/inc/os.h

添加头文件

#include <WS2tcpip.h>
#include <winbase.h>

修改1:

// #define str2int64 _atoi64
int64_t str2int64(char *str);

修改2:

// #define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap

修改3:

// #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
// #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_add_8 __sync_fetch_and_ad
#define atomic_fetch_add_16 __sync_fetch_and_add

修改4:

// char interlocked_and_fetch_8(char volatile* ptr, char val);
// short interlocked_and_fetch_16(short volatile* ptr, short val);
long interlocked_and_fetch_32(long volatile* ptr, long val);
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); // #define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
// #define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))

修改5:

// #define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
// #define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))

修改6:

// char interlocked_or_fetch_8(char volatile* ptr, char val);
// short interlocked_or_fetch_16(short volatile* ptr, short val);
long interlocked_or_fetch_32(long volatile* ptr, long val);
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); // #define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
// #define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))

修改7:

// #define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
// #define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))

修改8:

// char interlocked_xor_fetch_8(char volatile* ptr, char val);
// short interlocked_xor_fetch_16(short volatile* ptr, short val);
long interlocked_xor_fetch_32(long volatile* ptr, long val);
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); // #define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
// #define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))

修改9:

// #define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
// #define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))

修改10:

// #define MILLISECOND_PER_SECOND (1000i64)
#define MILLISECOND_PER_SECOND (1000LL)

src/os/windows/src/twindows.c

添加头:

#include <intrin.h>
#include <winbase.h>
#include <Winsock2.h>

修改1:

// add
// char interlocked_add_fetch_8(char volatile* ptr, char val) {
// return _InterlockedExchangeAdd8(ptr, val) + val;
// } // short interlocked_add_fetch_16(short volatile* ptr, short val) {
// return _InterlockedExchangeAdd16(ptr, val) + val;
// } char interlocked_add_fetch_8(char volatile* ptr, char val) {
return __sync_fetch_and_add(ptr, val) + val;
} short interlocked_add_fetch_16(short volatile* ptr, short val) {
return __sync_fetch_and_add(ptr, val) + val;
}

修改2:

// and
// char interlocked_and_fetch_8(char volatile* ptr, char val) {
// return _InterlockedAnd8(ptr, val) & val;
// } // short interlocked_and_fetch_16(short volatile* ptr, short val) {
// return _InterlockedAnd16(ptr, val) & val;
// }

修改3:

// or
// char interlocked_or_fetch_8(char volatile* ptr, char val) {
// return _InterlockedOr8(ptr, val) | val;
// } // short interlocked_or_fetch_16(short volatile* ptr, short val) {
// return _InterlockedOr16(ptr, val) | val;
// }

修改4:

// xor
// char interlocked_xor_fetch_8(char volatile* ptr, char val) {
// return _InterlockedXor8(ptr, val) ^ val;
// } // short interlocked_xor_fetch_16(short volatile* ptr, short val) {
// return _InterlockedXor16(ptr, val) ^ val;
// }

修改5:

添加以下代码

int64_t str2int64(char *str) {
char *endptr = NULL;
return strtoll(str, &endptr, 10);
} uint64_t htonll(uint64_t val)
{
return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32);
}

src/inc/taos.h

将要导出的函数添加

__declspec(dllexport)

例如:

__declspec(dllexport) void  taos_init();

需要导出的函数见 src/client/src/taos.def

cmake 转换

Configure 选择 MSYSMakefiles

Generator

make

进到转换后的目录执行 make

成功之后在编译目录的 build/bin 文件夹可以看到生成 taos.exe

build/lib 下存在以下文件

  • libiconv.a
  • libos.a
  • libpthread.a
  • libregex.a
  • libtaos.dll
  • libtaos.dll.a
  • libtals_static.a
  • libtrpc.a
  • libutil.a

cgo 使用

我们只需要关注 libtaos.dlllibtaos.dll.a

go 文件使用:

/*
#cgo CFLAGS : -I(taos.h文件文件夹)
#cgo LDFLAGS: (libtaos.dll.a文件位置)
*/

例如:

/*
#cgo CFLAGS : -IE:/software/msys64/usr/local/include
#cgo LDFLAGS: E:/software/msys64/usr/local/lib/libtaos.dll.a
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h>
*/
import "C"

运行时

程序运行时将 libtaos.dll 放到程序同级目录,需要保证服务端版本也是1.6.4.4。若版本不同请使用官方动态库改名使用(见注)。

注: 由于使用纯c编写使用vc编译器编译的动态库可以由 gcc 调用,所以官方提供的 taos.dll 可以改名为 libtaos.dll 使用。

基于TDengine-ver-1.6.4.4在windows 10下cmake+msys2编译(windows cgo 使用)的更多相关文章

  1. iOS冰与火之歌(番外篇) - 基于PEGASUS(Trident三叉戟)的OS X 10.11.6本地提权

    iOS冰与火之歌(番外篇) 基于PEGASUS(Trident三叉戟)的OS X 10.11.6本地提权 蒸米@阿里移动安全 0x00 序 这段时间最火的漏洞当属阿联酋的人权活动人士被apt攻击所使用 ...

  2. windows平台下基于VisualStudio的Clang安装和配置

    LLVM 是一个开源的编译器架构,它已经被成功应用到多个应用领域.Clang是 LLVM 的一个编译器前端,它目前支持 C, C++, Objective-C 以及 Objective-C++ 等编程 ...

  3. 基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出

    数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在之前的一篇文章<Winform开发框架之通用数据导入导出操作>介绍了在Winform ...

  4. Windows 环境下基于 nginx 的本地 PyPI 源

    Windows 环境下基于 nginx 的本地 PyPI 源的搭建: 1.登录 nginx 官网,下载安装包

  5. Windows 7下 搭建 基于 ssh 的sftp 服务器

    Windows  xp 下 搭建 基于  ssh 的sftp 服务器,服务器端可以用 freesshd,F-secure server等,filezilla server不可用,之前傻乎乎的用file ...

  6. windows平台下基于QT和OpenCV搭建图像处理平台

        在之前的博客中,已经分别比较详细地阐述了"windows平台下基于VS和OpenCV"以及"Linux平台下基于QT和OpenCV"搭建图像处理框架,并 ...

  7. 基于Windows环境下cmd/编译器无法输入中文,显示中文乱码解决方案

    基于Windows环境下cmd/编译器无法输入中文,显示中文乱码解决方案 两个月前做C++课设的时候,电脑编译器编译结果出现了中文乱码,寻求了百度和大神们,都没有解决这个问题,百度上一堆解释是对编译器 ...

  8. Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具)

    Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具) 最近因为项目关系,收朋友之托,想制作秀场网站,但是因为之前一直没有涉及到这 ...

  9. 基于Mysql-Proxy实现Mysql的主从复制以及读写分离(下)

    基于Mysql-Proxy实现Mysql的主从复制以及读写分离(下) 昨天谈到了Mysql实现主从复制,但由于时间原因并未讲有关读写分离的实现,之所以有读写分离,是为了使数据库拥有双机热备功能,至于双 ...

随机推荐

  1. Arthas用法

    简介 Arthas 是Alibaba开源的Java诊断工具,深受开发者喜爱. 当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决: 这个类从哪个 jar 包加载的? 为什么会报各种类相关的 ...

  2. JS 的私有成员为什么钦定了 #?

    翻译自 tc39/proposal-class-fields 译者按:社区一直以来有一个声音,就是反对使用 # 声明私有成员.但是很多质疑的声音过于浅薄.人云亦云.其实 TC39 早就对此类呼声做过回 ...

  3. Libev源码分析05:Libev中的绝对时间定时器

    Libev中的超时监视器ev_periodic,是绝对时间定时器,不同于ev_timer,它是基于日历时间的.比如如果指定一个ev_periodic在10秒之后触发(ev_now() + 10),然后 ...

  4. laravel 5.5 登录验证码 captcha 引入

    https://blog.csdn.net/u013372487/article/details/79461730 前提: 开启Laravel 的用户认证功能 1.安装 Captcha 安装 Capt ...

  5. Project Euler Problem 24-Lexicographic permutations

    全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...

  6. @hdu - 6427@ Problem B. Beads

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 有 m 种不同颜色的珠子,颜色分别为 1~m,每一种颜色的珠子有 ...

  7. webstorm破解教程

    1.下载地址 官网:https://www.jetbrains.com/webstorm/ 下载好之后按照提示安装即可,这里就不再多说了.下面直接说说如何使用补丁破解. 2.使用补丁破解 (http: ...

  8. 请求(RequestInfo)

    请求类型 StringRequestInfo 用在 SuperSocket 命令行协议中. 你也可以根据你的应用程序的需要来定义你自己的请求类型. 例如, 如果所有请求都包含 DeviceID 信息, ...

  9. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

  10. Educational Codeforces Round 11、A B题

    A. Co-prime Array 题意:给你一个数列,要求构造两两相邻之间的数互质的数列,可以插入的数的小于10的9次方 思路:其实可以选择靠近10的9次方的最大的三个素数.然后按我下面的方法做就可 ...