针对AWS SDK构建C ++应用程序的问题 - 找不到aws / core / Aws.h

时间:2018-04-07 23:03:24

标签: c++ macos cmake aws-sdk

解决

需要在项目目录中添加以下内容以生成CMakeLists.txt文件:

include_directories(/usr/local/include)

我有点恼火,AWS教程中没有提到这一步 - 浪费了一天半的时间。无论如何,谢谢你的倾听。

原始问题

我开始使用AWS C ++ SDK,而且我已经遇到了令人沮丧的障碍。

我已经使用here描述的程序在MacOS上下载,构建和安装了SDK(从“从源代码构建SDK”开始)。通过运行sudo make install在/ usr / local下部署了标头和库。

我写了一个愚蠢的小EC2测试程序:

#include <aws/core/Aws.h>
#include <aws/ec2/EC2Client.h>
#include <iostreams>

int main(int argc, char** argv)
{
   Aws::SDKOptions options;

   options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;

   Aws::InitAPI(options);
   {
      Aws::EC2::EC2Client my_client;
      std::cout << "created client" << std::endl;
   }
   Aws::ShutdownAPI(options);
   return 0;
}

不要担心代码的逻辑,因为我还没有那么远。

测试程序位于名为cpp-experiments的目录中。在同一级别,我创建了一个cpp-experiments-build目录。我正在使用CMake按如下方式设置构建:

cmake -Daws-sdk-cpp_DIR=/usr/local ../cpp-experiments

给出了以下输出:

jbode:cpp-experiments-build john.bode$ cmake -Daws-sdk-cpp_DIR=../aws-sdk-cpp-build ../cpp-experiments
-- The C compiler identification is AppleClang 9.0.0.9000039
-- The CXX compiler identification is AppleClang 9.0.0.9000039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/john.bode/Development/AWS/cpp-experiments-build

我从裸骨CMakeLists.txt开始 - 在这里和其他地方进行了一些随机谷歌搜索后,我结束了以下内容:

# minimal CMakeLists.txt for the AWS SDK for C++
cmake_minimum_required(VERSION 2.8)

# "my-example" is just an example value.
project(cpp-experiments)

set(AWS_CPP_SDK_INCLUDE_DIRS /usr/local/include CACHE STRING "aws-cpp-sdk include directories")
set(AWS_CPP_SDK_CORE_LIB "-l:/usr/local/lib/libaws-cpp-sdk-core.so" CACHE STRING "aws-cpp-sdk link core lib")
set(AWS_CPP_SDK_S3_LIB "-l:/usr/local/lib/libaws-cpp-sdk-ec2.so" CACHE STRING "aws-cpp-sdk link EC2 lib")

# Locate the AWS SDK for C++ package.
# Requires that you build with:
#   -Daws-sdk-cpp_DIR=/path/to/sdk_build
# or export/set:
#   CMAKE_PREFIX_PATH=/path/to/sdk_build
find_package(aws-sdk-cpp)

# Link to the SDK shared libraries.
add_definitions(-DUSE_IMPORT_EXPORT)

# The executable name and its sourcefiles
add_executable(cpp-experiments cpp-experiments.cpp)

# The libraries used by your executable.
# "aws-cpp-sdk-s3" is just an example.
target_link_libraries(cpp-experiments aws-sdk-cpp-core aws-sdk-cpp-ec2)

然后我进入cpp-experiments-build并运行make

jbode:cpp-experiments-build john.bode$ make
Scanning dependencies of target cpp-experiments
[ 50%] Building CXX object CMakeFiles/cpp-experiments.dir/cpp-experiments.cpp.o
/Users/john.bode/Development/AWS/cpp-experiments/cpp-experiments.cpp:1:10: fatal error: 'aws/core/Aws.h' file not found
#include <aws/core/Aws.h>
         ^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/cpp-experiments.dir/cpp-experiments.cpp.o] Error 1
make[1]: *** [CMakeFiles/cpp-experiments.dir/all] Error 2
make: *** [all] Error 2

如果我针对SDK构建目录运行cmake,我会得到相同的结果:

cmake -Daws-sdk-cpp_DIR=../aws-sdk-cpp-build ../cpp-experiments

现在,根据AWS文档,我已经完成了我需要做的所有事情,但显然情况并非如此 - 由于某种原因,make不知道AWS头文件的位置。我已经尝试在-I /usr/local/include命令行上传递make,但这也不起作用。有人能给我一个想要寻找什么的线索吗?

0 个答案:

没有答案