ベースTDengine-VER-1.6.4.4ウィンドウ+ msys2 10 cmakeの下でコンパイルされた(Windowsが使用するCGO)
背景
TDengineの行くコネクタは、ここでのgccコンパイラの窓のステップとTDengineを提供し、CGOのliunxを使用し、唯一のシステムで使用される、コンパイラVCからのウィンドウがまとめたダイナミックライブラリ、使用できないCGO提供しました彼は、コンパイル終了後。
最優先!クロスコンパイルの動的ライブラリは、品質を保証するものではありません!注意して本番環境!注意!注意!公式が提供するプロダクション環境 taos.dll **は、名前を変更libtaos.dll **使用を
ダウンロード
のみリリースgithubのをダウンロードするためにここにジャンプしてくださいダウンロードしたいコンパイル手順を見たいと思ってはいけません
倉庫住所
インストールと展開msys2
インストール
https://mirror.tuna.tsinghua.edu.cn/help/msys2/
インストール後に開いたC:\ msys64 \ msys2_shell.cmd右クリックウィンドウで、[オプション]を選択し、文字セットを変更ZH_CN GBK
変更パックマン設定ページ上でご覧ください(このステップははしごを省略することができる)
を行うには、修飾します
pacman -S mingw-w64-x86_64-gcc
設定の環境変数
C:\ msys64 \にMinGW64 \ビン
C:\ msys64 \ USR \ビン
システム変数パスに上記の順序で添加
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 /クライアント/ 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;
}
/窓/ 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 /クライアント/ SRC / taos.defを見ます
cmakeの変換
[設定]を選択しMSYSMakefilesを
発生器
メイク
ディレクトリは、実行メイクに変換
成功したビルドディレクトリの後のビルド/ binにあなたが生成されたファイルを見ることができますフォルダtaos.exe
ビルド/ libに以下のファイルの存在を
- libiconv.a
- libos.a
- libpthread.a
- libregex.a
- libtaos.dll
- libtaos.dll.a
- libtals_static.a
- libtrpc.a
- libutil.a
CGOの使用
私達はちょうど焦点を当てる必要がありlibtaos.dllをしてlibtaos.dll.a
ゴーファイル:
/*
#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であることを確認する必要があります。異なる動的ライブラリは、(注を参照)を使用して名前を変更した場合の公式バージョンを使用してください。
注: VCのダイナミックライブラリを使って書かれた純粋なCコンパイラを使用するためにはそう公式に、GCCによって呼び出すことができますtaos.dll名前を変更することがlibtaos.dll使用します。