Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined Reference to Aws::Transfer::TransferManager in AndroidStudio build #584

Closed
AWSCPP opened this issue Jun 22, 2017 · 19 comments
Closed
Labels
guidance Question that needs advice or information.

Comments

@AWSCPP
Copy link

AWSCPP commented Jun 22, 2017

Hello All,
I have cross-compiled the aws cpp for Android build and generated the shared libraries.
I would like to include these shared libraries in my Android application. My Android application will use Aws Transfer to download the files from S3 bucket.

    TransferManagerConfiguration transferManagerConfig;
    transferManagerConfig.s3Client = m_s3Client;
    TransferManager transferManager(transferManagerConfig);

    // Test with default behavior of using file name as key
    auto requestPtr = transferManager.UploadFile(sourceFileName, bucket, TEST_FILE_KEY,
                                                 "text/plain", Aws::Map<Aws::String, Aws::String>());

When I run the above code in my application, I get undefined reference to UploadFile API. This code has been taken from TransferTests.cpp.

error: undefined reference to 'Aws::Transfer::TransferManager::UploadFile(Aws::String const&, Aws::String const&, Aws::String const&, Aws::String const&, std::map<Aws::String, Aws::String, std::lessAws::String, Aws::Allocator<std::pair<Aws::String const, Aws::String> > > const&)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

There is no undefined reference for the constructor or for the transferManager.

This issue is only happening with the TransferManager code.

If I use S3 to download from bucket it is working fine.

Can anyone suggest how to resolve this issue ?

@singku
Copy link
Contributor

singku commented Jun 22, 2017

Are you able to run the aws-cpp-sdk-transfer-tests binary built in aws-cpp-sdk-transfer-tests directory without this linking problem?

@AWSCPP
Copy link
Author

AWSCPP commented Jun 23, 2017

Do you mean I need to run the AndroidSDKTesting application in android and verify the linking?
Is there any other way I can run aws-cpp-sdk-transfer-tests in android.

@marcomagdy
Copy link
Contributor

The error means that you're not linking libaws-cpp-sdk-transfer to your application.

@AWSCPP
Copy link
Author

AWSCPP commented Jun 24, 2017

TestAWSCPP.zip

I am attaching a sample Android application that I have created for testing AWS Transfer using Android.
The attached zip contains aws-core, aws-s3 and aws-transfer libraries that were cross-compiled for Android.

To verify if the aws transfer symbols are present in the library, I have run the following command
nm libaws-cpp-sdk-transfer| grep "DownloadFile"

and I get the below
0002bbb4 T _ZN3Aws8Transfer15TransferManager12DownloadFileERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS_9AllocatorIcEEEESA_NS2_8functionIFPNS2_14basic_iostreamIcS5_EEvEEERKNS0_21DownloadConfigurationE
0002bf68 T _ZN3Aws8Transfer15TransferManager12DownloadFileERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS_9AllocatorIcEEEESA_SA_RKNS0_21DownloadConfigurationE

which means the symbols are defined.

Below is the linker error for reference
Error while executing 'C:\Users\TestUser\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build C:\Users\TestUser\AndroidStudioProjects\TestAWSCPP\app.externalNativeBuild\cmake\arm7Debug\armeabi-v7a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ........\build\intermediates\cmake\arm7\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\TestUser\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target armv7-none-linux-androideabi -gcc-toolchain C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fexceptions -std=c++11 -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ........\build\intermediates\cmake\arm7\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -LC:/Users/TestUser/AndroidStudioProjects/TestAWSCPP/app/prebuilt/armeabi-v7a -llog -laws-cpp-sdk-core -laws-cpp-sdk-s3 -laws-cpp-sdk-transfer -lm "C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a" && cd ."
C:\Users\TestUser\AndroidStudioProjects\TestAWSCPP\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'Aws::Transfer::TransferManager::DownloadFile(Aws::String const&, Aws::String const&, Aws::String const&, Aws::Transfer::DownloadConfiguration const&)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Can anyone help with this issue?

@marcomagdy
Copy link
Contributor

The problem is the order you're using to link the libs.
They must be linked in reverse order of dependency So, aws-cpp-sdk-transfer should come before aws-cpp-sdk-s3 on the linker line, which in turn should be listed before aws-cpp-sdk-core.

@AWSCPP
Copy link
Author

AWSCPP commented Jun 26, 2017

Hi,

I have changed the order of linkage and tried again, but I am facing the same issue.

  • What went wrong:
    Execution failed for task ':app:externalNativeBuildArm7Debug'.

Build command failed.
Error while executing 'C:\Users\TestUser\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build C:\Users\TestUser\AndroidStudioProjects\TestAWSCPP\app.externalNativeBuild\cmake\arm7Debug\armeabi-v7a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ........\build\intermediates\cmake\arm7\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\TestUser\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target armv7-none-linux-androideabi -gcc-toolchain C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fexceptions -std=c++11 -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ........\build\intermediates\cmake\arm7\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -LC:/Users/TestUser/AndroidStudioProjects/TestAWSCPP/app/prebuilt/armeabi-v7a -llog -laws-cpp-sdk-transfer -laws-cpp-sdk-s3 -laws-cpp-sdk-core -lm "C:/Users/TestUser/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a" && cd ."
C:\Users\TestUser\AndroidStudioProjects\TestAWSCPP\app\src\main\cpp/native-lib.cpp:56: error: undefined reference to 'Aws::Transfer::TransferManager::DownloadFile(Aws::String const&, Aws::String const&, Aws::String const&, Aws::Transfer::DownloadConfiguration const&)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

If it was linker error for the libraries, I should have got an undefined reference for the constructor TransferManager too. But I am getting it only for the APIs such as UploadFile, DownloadFile etc.

Any other inputs?

@AWSCPP
Copy link
Author

AWSCPP commented Jun 27, 2017

Is this an issue related to compiling 32-bit or 64-bit libraries?
Can anyone tell me from the command line (pasted in the previous post) for linking if this could be the issue.

@singku
Copy link
Contributor

singku commented Jun 28, 2017

Unresolved symbols is a runtime error. Mostly triggered by libs not found. Since you dynamically linked to these libs. Are you sure the path of these libs is in loader's search list?

@AWSCPP
Copy link
Author

AWSCPP commented Jul 4, 2017

Hello,
Can anyone share any sample Android application that they have built using AWS Transfer.
I am not able to get this running for over a week and it is killing me.

@singku
Copy link
Contributor

singku commented Jul 4, 2017

Can you comment out all aws related code but construct of transfer manager to verify that the lib is actually linked but the Upload and Download symbols can't be found

@AWSCPP
Copy link
Author

AWSCPP commented Jul 4, 2017

I have linked the latest libraries and modified my code to create shared pointer of Transfer Manager using TransferManager::Create API . This is not giving any linking error during compilation.

@singku
Copy link
Contributor

singku commented Jul 4, 2017

The error msg is
error: undefined reference to Aws::Transfer::TransferManager::UploadFile(Aws::String const&, Aws::String const&, Aws::String const&, Aws::String const&, std::map<Aws::String, Aws::String, std::lessAws::String, Aws::Allocator<std::pair<Aws::String const, Aws::String> > > const&)

but nm output
_ZN3Aws8Transfer15TransferManager12DownloadFileERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS_9AllocatorIcEEEESA_NS2_8functionIFPNS2_14basic_iostreamIcS5_EEvEEERKNS0_21DownloadConfigurationE

Looks like extern "C" affected the name of functions to be looked up

@AWSCPP
Copy link
Author

AWSCPP commented Jul 4, 2017

So is it an issue related to compilation of aws sdk libraries or is something missing in my cpp code?

@singku
Copy link
Contributor

singku commented Jul 4, 2017

Can you try removing extern "C" from your native-lip.cpp (maybe you also need to change the return type, but just do a trial) and see if it works.

Update: But extern "C" should only affect those code inside { } and if it is the problem, function name of constructor should also be affected. And you would also have problem to find the symbol of constructor.

@AWSCPP
Copy link
Author

AWSCPP commented Jul 4, 2017

There is no extern C in my native-lib.cpp code.

Actually I have not compiled the aws sdk in Android studio. I have separately cross compiled the sdk in an Ubuntu platform and am trying to use those prebuilt libraries in my android project. So my code changes will not have any impact on the sdk libraries

@singku
Copy link
Contributor

singku commented Jul 4, 2017

But I saw one from the code you attached above.

@AWSCPP
Copy link
Author

AWSCPP commented Jul 5, 2017

Sorry.
I have removed extern "C" from my native-lib.cpp and tried , but the issue persists.

@singku
Copy link
Contributor

singku commented Jul 5, 2017

Hi, I can see you build out a dynamic library called libnative-lib.so, could you have look at the aws sdk related symbols' name in this library?

@AWSCPP AWSCPP closed this as completed Jul 21, 2017
@singku
Copy link
Contributor

singku commented Jul 21, 2017

Are you able to figure it out?

@justnance justnance added guidance Question that needs advice or information. and removed question labels Apr 19, 2019
aws-sdk-cpp-automation pushed a commit that referenced this issue Nov 6, 2019
README update for xcode build
thesunisgas pushed a commit to thesunisgas/aws-sdk-cpp that referenced this issue May 19, 2020
README update for xcode build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants