简体   繁体   English

使用AWS C ++ SDK的基本程序无法编译

[英]Basic program using AWS C++ SDK won't compile

I'm having some troubles using AWS C++ SDK, due to a serious lack of documentation. 由于严重缺乏文档,我在使用AWS C ++ SDK时遇到了一些麻烦。 However I managed to compile and install it on my computer. 但是我设法在我的计算机上编译并安装它。

I'm now trying hard to have a program working and resolved quite a lot of problems, but a (hopefully) last one remains that I cannot defeat alone... 我现在正在努力让一个程序工作并解决了很多问题,但是(希望)最后一个仍然是我无法独自战胜......

Here is the code : 这是代码:

#include <aws/s3/model/GetObjectRequest.h>

int main()
{
     Aws::S3::Model::GetObjectRequest getObjectRequest;
}

I tried to have the simplest code for my example. 我试着为我的例子提供最简单的代码。 That code doesn't compile, I've got the following error : 该代码无法编译,我有以下错误:

CMakeFiles/example.dir/example.cpp.o:(.rodata._ZTIN3Aws2S39S3RequestE[_ZTIN3Aws2S39S3RequestE]+0x10): undefined reference to `typeinfo for Aws::AmazonSerializableWebServiceRequest'

I don't get what the problem is. 我不知道问题是什么。 I tried checking in the source code of the library, and no pure virtual function remains in the GetObjectRequest class. 我尝试检查库的源代码,GetObjectRequest类中没有纯虚函数。 I think I linked correctly the libraries. 我想我正确地链接了库。 Here is my CMakeLists.txt : 这是我的CMakeLists.txt:

project( TEST_AWS )
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
add_definitions ( -Wall -Wextra )

set(LIBAWSSDK_INCLUDE_DIR /usr/local/include/ CACHE STRING "aws SDK include directories")
set(LIBAWSSDK_CORE_LIB "-l:/usr/local/lib/libaws-cpp-sdk-core.so" CACHE STRING "aws SDK core link lib")
set(LIBAWSSDK_S3_LIB "-l:/usr/local/lib/libaws-cpp-sdk-s3.so" CACHE STRING "aws SDK S3 link lib")

set(target_external_libraries
    ${LIBAWSSDK_CORE_LIB}
    ${LIBAWSSDK_S3_LIB}
)

include_directories(
    ${LIBAWSSDK_INCLUDE_DIR}
)

add_executable( example example.cpp )
target_link_libraries( example ${target_external_libraries} )
target_compile_features(example PRIVATE cxx_lambdas)

I know the way I linked the library with cmake is a little bit dirty, but for the moment I just want the code to compile... 我知道我用cmake链接库的方式有点脏,但目前我只想编译代码...

If you are using CMake, I recommend using the cmake export file from the SDK to avoid having to figure out what we are using. 如果您使用的是CMake,我建议您使用SDK中的cmake导出文件,以避免弄清楚我们使用的是什么。 https://aws.amazon.com/blogs/developer/using-cmake-exports-with-the-aws-sdk-for-c/ https://aws.amazon.com/blogs/developer/using-cmake-exports-with-the-aws-sdk-for-c/

The -fno-rtti flag will be removed and changed to an optional CMake flag. -fno-rtti标志将被删除并更改为可选的CMake标志。

If you use the CMake exports, it will properly generate your visual studio solution. 如果您使用CMake导出,它将正确生成您的visual studio解决方案。

Update: 更新:

This has been fixed with the latest revision 这已通过最新版本修复

  • Very important: If you're compiling with RTTI (-frtti), make sure your dependent libraries are also compiled with it, and not -fno-rtti. 非常重要:如果您正在使用RTTI(-frtti)进行编译,请确保您的依赖库也使用它进行编译,而不是-fno-rtti。 Otherwise you will get the typeinfo error when you subclass a class compiled with -fno-rtti or use dynamic_cast. 否则,在子类化使用-fno-rtti编译的类或使用dynamic_cast时,将获得typeinfo错误。 ( C++: what are the causes of " undefined reference to 'typeinfo for [class name]' "other than virtual functions ) C ++:除了虚函数之外,对'class name]'的'typeinfo'未定义引用“的原因是什么?

  • So, the -fno-rtti works only if you are compiling just the aws-sdk 因此,只有在编译aws-sdk时,-fno-rtti才有效

  • Now, for most cases, there'll be many many other libraries that you will be compiling the aws-sdk with. 现在,对于大多数情况,你将使用许多其他库来编译aws-sdk。 Most libraries, opencv, etc are compiled with -frtti. 大多数库,opencv等都是用-frtti编译的。 If aws-sdk is compiled with -fno-rtti, then you will get the above typeinfo madness error 如果用-fno-rtti编译aws-sdk,那么你将得到上面的typeinfo madness错误

  • Solution: checkout the latest aws-sdk-cpp (as of June 1st). 解决方案:查看最新的aws-sdk-cpp(截至6月1日)。 It uses the -frtti option..and then link against it, and Life is good 它使用-frtti选项..然后链接它,生活是好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM