update readme
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
examples/README_zh.md
Normal file
59
examples/README_zh.md
Normal file
@@ -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 目录下的可执行文件,
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user