Explorar el Código

update readme

zhangzifa hace 7 años
padre
commit
f877a9ef39
Se han modificado 10 ficheros con 458 adiciones y 158 borrados
  1. 163 84
      README.md
  2. 92 44
      README_zh.md
  3. 3 1
      easyinstall.sh
  4. 0 12
      examples/CMakeLists.txt
  5. 29 9
      examples/README.md
  6. 59 0
      examples/README_zh.md
  7. 1 1
      examples/ecs/CMakeLists.txt
  8. 35 3
      examples/utils.h
  9. 41 1
      test/core/utils.h
  10. 35 3
      test/function_test/utils.h

+ 163 - 84
README.md

@@ -1,84 +1,163 @@
-# Alibaba Cloud C++ Software Development Kit
-[中文文档](./README_zh.md)
-
-[![Build Status](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk)
-[![codecov](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk)
-
-The Alibaba Cloud C++ Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.
-
-This document introduces how to obtain and call Alibaba Cloud C++ SDK.
-
-If you have any problem while using C++ SDK, please submit an [issue](https://github.com/aliyun/aliyun-openapi-cpp-sdk/issues/new).
-
-## Prerequisites
-
-- To use Alibaba Cloud C++ SDK, you must have an Alibaba Cloud account and an AccessKey.
-
-	The AccessKey is required when initializing the client. You can create an AccessKey in the Alibaba Cloud console. For more information, see [Create an AccessKey](https://usercenter.console.aliyun.com/?spm=5176.doc52740.2.3.QKZk8w#/manage/ak).
-
-	>**Note:** To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.
-
-- To use Alibaba Cloud C++ SDK to access the APIs of a product, you must first activate the product on the [Alibaba Cloud console](https://home.console.aliyun.com/?spm=5176.doc52740.2.4.QKZk8w) if required.
-
-
-## Install C++ SDK
-
-1. Install third-party libraries on the Linux platform, including `libcurl`, `libopenssl`, `libuuid`, and `libjsoncpp`.
-
-	- Run the following commands on the Redhat/Fedora system to install third-party libraries.
-	```
-    sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
-    ```
-	- Run the following commands on the Debian/Ubuntu system to install third-party libraries.
-    ```
-    sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
-    ```
-2. Run the following commands to clone source codes from GitHub.
-
-    ```
-    git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
-    ```
-
-## Use the C++ SDK
-
-Before using C++ SDK, you must first configure the preprocessor to define `ALIBABACLOUD_SHARED` to achieve dynamic linking with Alibaba Cloud C++ SDK shared libraries. Then you must create a client instance, specify the region of cloud services and provide authentication parameters before sending API requests.
-
-The following code shows how to call the [DescribeInstances](~~25506~~) API of ECS to query detailed information of all ECS instances in a specific region.
-
-```cpp
-#include <iostream>
-#include <alibabacloud/core/AlibabaCloud.h>
-#include <alibabacloud/ecs/EcsClient.h>
-
-using namespace AlibabaCloud;
-using namespace AlibabaCloud::Ecs;
-
-int main(int argc, char** argv)
-{
-	// Initialize the SDK
-	AlibabaCloud::InitializeSdk();
-
-	// Configure the ECS instance
-	ClientConfiguration configuration("<your-region-id>");
-	EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
-
-	// Create an API request and set parameters
-	Model::DescribeInstancesRequest request;
-	request.setPageSize(10);
-
-	auto outcome = client.describeInstances(request);
-	if (!outcome.isSuccess())
-	{
-		// Handle exceptions
-		std::cout << outcome.error().errorCode() << std::endl;
-		AlibabaCloud::ShutdownSdk();
-		return -1;
-	}
-
-	std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
-
-	// Close the SDK
-	AlibabaCloud::ShutdownSdk();
-	return 0;
-}
-```
+# Alibaba Cloud C++ Software Development Kit
+[中文文档](./README_zh.md)
+
+[![Build Status](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk)
+[![codecov](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk)
+
+The Alibaba Cloud C++ Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.
+
+This document introduces how to obtain and call Alibaba Cloud C++ SDK.
+
+If you have any problem while using C++ SDK, please submit an [issue](https://github.com/aliyun/aliyun-openapi-cpp-sdk/issues/new).
+
+## Prerequisites
+
+- To use Alibaba Cloud C++ SDK, you must have an Alibaba Cloud account and an AccessKey.
+
+	The AccessKey is required when initializing the client. You can create an AccessKey in the Alibaba Cloud console. For more information, see [Create an AccessKey](https://usercenter.console.aliyun.com/?spm=5176.doc52740.2.3.QKZk8w#/manage/ak).
+
+	>**Note:** To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.
+
+- To use Alibaba Cloud C++ SDK to access the APIs of a product, you must first activate the product on the [Alibaba Cloud console](https://home.console.aliyun.com/?spm=5176.doc52740.2.4.QKZk8w) if required.
+
+- C++11 supported compiler installed
+  - Windows: Visual Studio 2015 or newer
+  - Linux: GCC 4.9 or newer
+- CMake 3.0 or newer
+- 4G memory or more
+
+## Install C++ SDK from source code
+
+
+### Linux
+
+1. Install third-party libraries on the Linux platform, including `libcurl`, `libopenssl`, `libuuid`, and `libjsoncpp`.
+
+	- Run the following commands on the `Redhat/Fedora` system
+	```
+    sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
+    ```
+	- Run the following commands on the `Debian/Ubuntu` system
+    ```
+    sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
+    ```
+2. Run the following commands to clone source codes from GitHub.
+
+    ```bash
+    git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
+    ```
+
+3. Build and install SDK
+
+  - Manually build and install
+
+  ```bash
+    cd aliyun-openapi-cpp-sdk
+    mkdir sdk_build
+    cd sdk_build
+    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
+    make
+    sudo make install
+  ```
+
+  - Or you may do this with `easyinstall.sh` in the source directory
+
+  ```shell
+    cd aliyun-openapi-cpp-sdk
+    sudo sh easyinstall.sh
+   ```
+
+**The C++ SDK will be installed to `/usr`.**
+
+### windows
+
+1. Install [perl](https://www.perl.org/get.html#win32).
+
+2. Run the following command to clone code from Github via git-bash:
+
+  ```bash
+  git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
+  ```
+
+2. Build Visual Studio solution
+
+- Change directory to source code and make directory sdk_build
+
+- Open CMake UI and
+
+  - `Browse Source` to open source code directory.
+
+  - `Browse build`  to open the created sdk_build directory
+
+  - `Configure`
+
+  - `Generate`
+
+3. Build and Install C++ SDK
+
+- Open `aliyun-openapi-cpp-sdk\\sdk_build\\alibabacloud-sdk.sln` with Visual Studio
+
+- Select  `Release`
+
+- Check INSTALL option from Build -> Configuration Manager
+
+- Build->Build Solutions to build.
+
+**SDK will be installed to `C:\Program File (x86)\alibabacloud-sdk`**
+
+
+## Use the C++ SDK
+
+Before using C++ SDK, you must first configure the preprocessor to define `ALIBABACLOUD_SHARED` to achieve dynamic linking with Alibaba Cloud C++ SDK shared libraries. Then you must create a client instance, specify the region of cloud services and provide authentication parameters before sending API requests.
+
+The following code shows how to call the [DescribeInstances](~~25506~~) API of ECS to query detailed information of all ECS instances in a specific region.
+
+```cpp
+#include <iostream>
+#include <alibabacloud/core/AlibabaCloud.h>
+#include <alibabacloud/ecs/EcsClient.h>
+
+using namespace AlibabaCloud;
+using namespace AlibabaCloud::Ecs;
+
+int main(int argc, char** argv) {
+  // Initialize the SDK
+  AlibabaCloud::InitializeSdk();
+
+  // Configure the ECS instance
+  ClientConfiguration configuration("<your-region-id>");
+  EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
+
+  // Create an API request and set parameters
+  Model::DescribeInstancesRequest request;
+  request.setPageSize(10);
+
+  auto outcome = client.describeInstances(request);
+  if (!outcome.isSuccess()) {
+    // Handle exceptions
+    std::cout << outcome.error().errorCode() << std::endl;
+    AlibabaCloud::ShutdownSdk();
+    return -1;
+  }
+
+  std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
+
+  // Close the SDK
+  AlibabaCloud::ShutdownSdk();
+  return 0;
+}
+```
+
+Copy the above to ecs_test.cc, then build with the following command.
+
+```bash
+~$ g++ -o ecstest ecs_test.cc --std=c++11 -lalibabacloud-sdk-core -l alibabacloud-sdk-ecs
+~$ ./ecstest
+# Result or error message will be shown here.
+~$
+```
+
+**More [examples](https://github.com/aliyun/aliyun-openapi-cpp-sdk/tree/master/examples)**
+
+## LICENSE
+Please refer to [LICENSE](https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/LICENSE) (Apache 2.0 LICENSE).

+ 92 - 44
README_zh.md

@@ -22,8 +22,11 @@
 * 开通了云产品服务。有些云产品如对象存储(OSS)需要先在[阿里云控制台](https://home.console.aliyun.com)开通服务。
 
 * 安装支持 C++ 11 或更高版本的编译器:
-	* Visual Studio 2015 或以上版本
-	* 或 GCC 4.9 或以上版本
+	* Windows: Visual Studio 2015 或以上版本
+	* Linux: GCC 4.9 或以上版本
+
+* 安装 CMake 3.0 或以上版本
+* 建议 4G 或以上内存
 
 ## 从源代码构建 SDK
 
@@ -36,43 +39,77 @@
 git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
 ```
 
-2. 安装 cmake 3.0 或以上版本,进入 SDK 创建生成必要的构建文件
+2. 创建生成必要的构建文件
 
-```
+```bash
 cd <path/to/aliyun-openapi-cpp-sdk>
 mkdir sdk_build
 cd sdk_build
 cmake ..
 ```
 
-### Windows
+### Linux
 
-进入 sdk_build 目录使用 Visual Studio 打开 alibabacloud-sdk.sln 生成解决方案
+要在 Linux 平台进行编译, 您必须安装依赖的外部库文件 libcurl、libopenssl、libuuid、libjsoncpp, 通常情况下,系统的包管理器中的会有提供
 
-或者您也可以使用 VS 的开发人员命令提示符,执行以下命令编译并安装:
+例如:在基于 Redhat / Fedora 的系统上安装这些软件包
 
+```bash
+sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
 ```
-msbuild ALL_BUILD.vcxproj
-msbuild INSTALL.vcxproj
+
+在基于 Debian/Ubuntu 的系统
+```bash
+sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
 ```
 
-### Linux
+在安装依赖库后执行以下命令编译并安装:
 
-要在 Linux 平台进行编译, 您必须安装依赖的外部库文件 libcurl、libopenssl、libuuid、libjsoncpp, 通常情况下,系统的包管理器中的会有提供。
+手动编译安装
+```bash
+  cd aliyun-openapi-cpp-sdk
+  mkdir sdk_build
+  cd sdk_build
+  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
+  make
+  sudo make install
+```
 
-例如:在基于 Redhat / Fedora 的系统上安装这些软件包
+或者通过 `easyinstall.sh`一键式安装
 
-```
-sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
+```bash
+  cd aliyun-openapi-cpp-sdk
+  sudo sh easyinstall.sh
 ```
 
-在安装依赖库后执行以下命令编译并安装:
+**C++ SDK 将被安装在 `/usr`.**
+
+
+### Windows
+
+通过 cmake 生成 Visual Studio 解决方案:
+
+在 aliyun-openapi-cpp-sdk 下创建 sdk_build 目录
+
+打开 cmake-ui 选择源代码目录和构建目录,点击 `配置(configure)` 和 `生成(generate)` 构建 VS 解决方案。
+
+进入 sdk_build 目录使用 Visual Studio 打开 alibabacloud-sdk.sln 解决方案。
+
+选择构建 `Release` 输出,并打开配置管理器勾选 `INSTALL`。
+
+构建 -> 生成解决方案。
+
+或者您也可以使用 VS 的开发人员命令提示符,执行以下命令编译并安装:
 
 ```
-make
-sudo make install
+msbuild ALL_BUILD.vcxproj
+msbuild INSTALL.vcxproj
 ```
 
+**C++ SDK 将安装在 `C:\Program File (x86)\alibabacloud-sdk` 目录**
+
+**注意:请以管理员身份运行 Visual Studio,否则无法安装 SDK**
+
 ## 如何使用 C++ SDK
 
 在调用 C++ SDK时,您首先需要配置预处理器定义 ALIBABACLOUD_SHARED 以引用阿里云 C++ SDK 的共享库,然后通过创建 Client 实例提供身份验证,并指定云服务的地域,然后发送API请求。
@@ -89,35 +126,46 @@ sudo make install
 using namespace AlibabaCloud;
 using namespace AlibabaCloud::Ecs;
 
-int main(int argc, char** argv)
-{
-	// 初始化 SDK
-	AlibabaCloud::InitializeSdk();
-
-	// 配置 ecs 实例
-	ClientConfiguration configuration("<your-region-id>");
-	EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
-
-	// 创建API请求并设置参数
-	Model::DescribeInstancesRequest request;
-	request.setPageSize(10);
-
-	auto outcome = client.describeInstances(request);
-	if (!outcome.isSuccess())
-	{
-		// 异常处理
-		std::cout << outcome.error().errorCode() << std::endl;
-		AlibabaCloud::ShutdownSdk();
-		return -1;
-	}
-
-	std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
-
-	// 关闭 SDK
-	AlibabaCloud::ShutdownSdk();
-	return 0;
+int main(int argc, char** argv) {
+  // 初始化 SDK
+  AlibabaCloud::InitializeSdk();
+
+  // 配置 ecs 实例
+  ClientConfiguration configuration("<your-region-id>");
+  EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
+
+  // 创建API请求并设置参数
+  Model::DescribeInstancesRequest request;
+  request.setPageSize(10);
+
+  auto outcome = client.describeInstances(request);
+  if (!outcome.isSuccess()) {
+    // 异常处理
+    std::cout << outcome.error().errorCode() << std::endl;
+    AlibabaCloud::ShutdownSdk();
+    return -1;
+  }
+
+  std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
+
+  // 关闭 SDK
+  AlibabaCloud::ShutdownSdk();
+  return 0;
 }
 ```
 
+复制上述文件到 ecs_test.cc。
+
+Linux 下
+
+```bash
+~$ g++ -o ecstest ecs_test.cc --std=c++11 -lalibabacloud-sdk-core -l alibabacloud-sdk-ecs
+~$ ./ecstest
+# 结果或错误返回将在此展示
+~$
+```
+
+**更多 [例程](https://github.com/aliyun/aliyun-openapi-cpp-sdk/tree/master/examples) 请(参考)[https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/examples/README_zh.md]**
+
 ## 许可协议
 请参阅 LICENSE 文件(Apache 2.0 许可证)。

+ 3 - 1
build_sdk.sh → easyinstall.sh

@@ -10,5 +10,7 @@ echo $MAKE
 rm -rf sdk_build
 mkdir sdk_build
 cd sdk_build
-cmake -DBUILD_FUNCTION_TESTS=OFF -DBUILD_UNIT_TESTS=OFF -DENABLE_COVERAGE=OFF ..
+cmake -DBUILD_FUNCTION_TESTS=OFF -DBUILD_UNIT_TESTS=OFF -DENABLE_COVERAGE=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
 $MAKE
+
+make install

+ 0 - 12
examples/CMakeLists.txt

@@ -6,18 +6,6 @@ project(alibabacloud-sdk-examples)
 
 set(CMAKE_CXX_STANDARD 11)
 
-message("include dir: " ${CMAKE_SOURCE_DIR}/../core/include)
-
-include_directories("${CMAKE_SOURCE_DIR}/../core/include/")
-include_directories("${CMAKE_SOURCE_DIR}/../cdn/include/")
-include_directories("${CMAKE_SOURCE_DIR}/../ecs/include/")
-include_directories("${CMAKE_SOURCE_DIR}/../rds/include/")
-include_directories("${CMAKE_SOURCE_DIR}/../slb/include/")
-include_directories("${CMAKE_SOURCE_DIR}/../vpc/include/")
-
-
-link_directories(${CMAKE_SOURCE_DIR}/../sdk_build/lib)
-
 add_subdirectory(imagesearch)
 add_subdirectory(nlp)
 add_subdirectory(rds)

+ 29 - 9
examples/README.md

@@ -1,14 +1,11 @@
 # how to use examples
 
-## 1. install sdk
-
-```bash
-cd path/to/aliyun-openapi-cpp-sdk
-./build_sdk.sh
-```
+## 1. Install SDK according to [README](https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/README.md)
 
 ## 2. build examples
 
+### Linux
+
 ```bash
 cd path/to/aliyun-openapi-cpp-sdk
 cd examples
@@ -18,16 +15,33 @@ cmake ..
 make -j
 ```
 
+### Windows
+
+- Generate Visual Studio solution with the same way as buidl SDK.
+
+  - Run cmake-ui
+
+  - select source code path(examples dir) and build path (create build dir in examples dir).
+
+  - configure
+
+  - generate
+
+- Open `alibabacloud-sdk-examples.sln` in build directory.
+
+- Build -> Build Solution
+
+
 ## 3. run examples
 
-configure `accessKeyId` and `accessKeySecret` via env.
+### Linux
+
+- configure `accessKeyId` and `accessKeySecret` via env and then Run.
 
 ```bash
 export ENV_AccessKeyId="your-accessKeyId"
 export ENV_AccessKeySecret="your-accessKeySecret"
-```
 
-```bash
 cd path/to/aliyun-openapi-cpp-sdk
 cd examples/build/bin
 
@@ -35,3 +49,9 @@ cd examples/build/bin
 ./ecs_demo
 ...
 ```
+
+### Windows
+
+Configure env according to your windows OS.
+
+Run .exe file in command window in directory build\\bin\\Release

+ 59 - 0
examples/README_zh.md

@@ -0,0 +1,59 @@
+# 如何运行例程
+
+## 1. 根据 [README](https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/README_zh.md) 安装 SDK
+
+## 2. 构建例程
+
+### Linux
+
+```bash
+cd path/to/aliyun-openapi-cpp-sdk
+cd examples
+mkdir build
+cd build
+cmake ..
+make -j
+```
+
+### Windows
+
+- 通过 CMake 构建 Visual Studio 解决方案
+
+  - 运行 cmake-ui
+
+  - 选在源代码目录(examples 目录)和构建目录(在 examples 创建 build 目录)。
+
+  - 配置 (configure)
+
+  - 生成 (generate)
+
+- 用 Visual Studio 从 build 目录打开 `alibabacloud-sdk-examples.sln`
+
+- 编译: 生成 -> 生成解决方案
+
+
+## 3. 运行例程
+
+### Linux
+
+- 配置环境变量 `accessKeyId` and `accessKeySecret`
+
+```bash
+export ENV_AccessKeyId="your-accessKeyId"
+export ENV_AccessKeySecret="your-accessKeySecret"
+```
+
+```bash
+cd path/to/aliyun-openapi-cpp-sdk
+cd examples/build/bin
+
+# run ecs_demo
+./ecs_demo
+...
+```
+
+### Windows
+
+根据您的 Windows 版本设置环境变量
+
+- 在命令行窗口直接运行 build\\bin\\Releaes 目录下的可执行文件,

+ 1 - 1
examples/ecs/CMakeLists.txt

@@ -9,7 +9,7 @@ endif()
 add_executable(ecs_demo ecs.cc)
 target_link_libraries(ecs_demo alibabacloud-sdk-core alibabacloud-sdk-ecs)
 
-target_link_libraries(ecs_demo )
+target_link_libraries(ecs_demo)
 
 set_target_properties(ecs_demo
   PROPERTIES

+ 35 - 3
examples/utils.h

@@ -1,11 +1,30 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <unistd.h>
+#endif
 
 class utUtils {
  public:
   void get_dir_exec(char* dir, char* exec) {
+#ifdef _WIN32
+  char BufferFileName[MAX_PATH];
+  memset(BufferFileName,0,MAX_PATH);
+  if (GetModuleFileName(NULL, BufferFileName, MAX_PATH)) {
+    if (exec) {
+      snprintf(exec, strlen(BufferFileName), "%s", BufferFileName);
+    }
+
+    std::string ss(BufferFileName);
+    int idx = ss.find_last_of("\\");
+    BufferFileName[idx] = '\0';
+    snprintf(dir, strlen(BufferFileName), "%s", BufferFileName);
+  }
+  return;
+#else
     char* filename = nullptr;
     if (readlink("/proc/self/exe", dir, 1024) < 0) {
       dir[0] = '\0';
@@ -23,16 +42,29 @@ class utUtils {
 
     *filename = '\0';
     return;
+#endif
   }
 
+
   std::string get_env(const std::string env) {
+
+#ifdef _WIN32
+  char* buf = nullptr;
+  size_t sz = 0;
+  if (_dupenv_s(&buf, &sz, env.c_str()) == 0 && buf != nullptr) {
+      std::string var(buf);
+      free(buf);
+      return var;
+  } else {
+    return std::string();
+  }
+
+#else
     char* value = getenv(env.c_str());
     if (value == nullptr) {
       return std::string();
     }
     return std::string(value);
+#endif
   }
 };
-
-
-

+ 41 - 1
test/core/utils.h

@@ -1,11 +1,30 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <unistd.h>
+#endif
 
 class utUtils {
  public:
   void get_dir_exec(char* dir, char* exec) {
+#ifdef _WIN32
+  char BufferFileName[MAX_PATH];
+  memset(BufferFileName,0,MAX_PATH);
+  if (GetModuleFileName(NULL, BufferFileName, MAX_PATH)) {
+    if (exec) {
+      snprintf(exec, strlen(BufferFileName), "%s", BufferFileName);
+    }
+
+    std::string ss(BufferFileName);
+    int idx = ss.find_last_of("\\");
+    BufferFileName[idx] = '\0';
+    snprintf(dir, strlen(BufferFileName), "%s", BufferFileName);
+  }
+  return;
+#else
     char* filename = nullptr;
     if (readlink("/proc/self/exe", dir, 1024) < 0) {
       dir[0] = '\0';
@@ -23,8 +42,29 @@ class utUtils {
 
     *filename = '\0';
     return;
+#endif
   }
-};
 
 
+  std::string get_env(const std::string env) {
 
+#ifdef _WIN32
+  char* buf = nullptr;
+  size_t sz = 0;
+  if (_dupenv_s(&buf, &sz, env.c_str()) == 0 && buf != nullptr) {
+      std::string var(buf);
+      free(buf);
+      return var;
+  } else {
+    return std::string();
+  }
+
+#else
+    char* value = getenv(env.c_str());
+    if (value == nullptr) {
+      return std::string();
+    }
+    return std::string(value);
+#endif
+  }
+};

+ 35 - 3
test/function_test/utils.h

@@ -1,11 +1,30 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <unistd.h>
+#endif
 
 class utUtils {
  public:
   void get_dir_exec(char* dir, char* exec) {
+#ifdef _WIN32
+  char BufferFileName[MAX_PATH];
+  memset(BufferFileName,0,MAX_PATH);
+  if (GetModuleFileName(NULL, BufferFileName, MAX_PATH)) {
+    if (exec) {
+      snprintf(exec, strlen(BufferFileName), "%s", BufferFileName);
+    }
+
+    std::string ss(BufferFileName);
+    int idx = ss.find_last_of("\\");
+    BufferFileName[idx] = '\0';
+    snprintf(dir, strlen(BufferFileName), "%s", BufferFileName);
+  }
+  return;
+#else
     char* filename = nullptr;
     if (readlink("/proc/self/exe", dir, 1024) < 0) {
       dir[0] = '\0';
@@ -23,16 +42,29 @@ class utUtils {
 
     *filename = '\0';
     return;
+#endif
   }
 
+
   std::string get_env(const std::string env) {
+
+#ifdef _WIN32
+  char* buf = nullptr;
+  size_t sz = 0;
+  if (_dupenv_s(&buf, &sz, env.c_str()) == 0 && buf != nullptr) {
+      std::string var(buf);
+      free(buf);
+      return var;
+  } else {
+    return std::string();
+  }
+
+#else
     char* value = getenv(env.c_str());
     if (value == nullptr) {
       return std::string();
     }
     return std::string(value);
+#endif
   }
 };
-
-
-