aws / aws-iot-device-sdk-cpp

SDK for connecting to AWS IoT from a device using C++
http://aws-iot-device-sdk-cpp-docs.s3-website-us-east-1.amazonaws.com
Apache License 2.0
123 stars 112 forks source link

Confusion? #97

Closed ghost closed 6 years ago

ghost commented 6 years ago

I am attempting to build the SDK into a link library (static) for a project, but when I use the steps listed the cmake always fails telling me it can not successfully link (which is no surprise since I am just attempting to build a link library). Then it simply stops.

I want to avoid cherry picking the code out of the SDK to use in my project, is there any way/steps I can follow to simply build a library out of the SDK so that when the SDK is updated, all I have to do is rebuild a library to link to?

vareddy-zz commented 6 years ago

Hi @jflynn129, If you want a static library, when you run make it should build it by default. You will find the library in the build/archive as libaws-iot-sdk-cpp.a. Which step is it failing at? Does cmake ../. fail or does make fail? Could you post the output of the build here? Thanks! Varun

ghost commented 6 years ago

It fails during the config:

 Run Build Command:"/usr/bin/make" "cmTC_74da5/fast"

  /usr/bin/make -f CMakeFiles/cmTC_74da5.dir/build.make   CMakeFiles/cmTC_74da5.dir/build

  make[1]: Entering directory '/home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++   -std=c++11 -o CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj -c /home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

  Linking CXX executable cmTC_74da5

  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_74da5.dir/link.txt   --verbose=1

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++   -std=c++11 CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj -o cmTC_74da5

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o):   In function `exit':

  exit.c:(.text.exit+0x2c): undefined reference to `_exit'

  collect2: error: ld returned 1 exit status

  CMakeFiles/cmTC_74da5.dir/build.make:97: recipe for target 'cmTC_74da5'   failed

  make[1]: *** [cmTC_74da5] Error 1

  make[1]: Leaving directory '/home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_74da5/fast' failed

  make: *** [cmTC_74da5/fast] Error 2

  CMake will not be able to correctly generate this project. Call Stack (most recent call first):   CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

On 04/26/2018 07:23 PM, Varun Reddy wrote:

Hi @jflynn129 https://github.com/jflynn129, If you want a static library, when you run make it should build it by default. You will find the library in the |build/archive| as |libaws-iot-sdk-cpp.a|. Which step is it failing at? Does |cmake ../.| fail or does |make| fail? Could you post the output of the build here? Thanks! Varun

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-cpp/issues/97#issuecomment-384818255, or mute the thread https://github.com/notifications/unsubscribe-auth/AR0LLldFUJJ02g3mlm5t7YQy0wUcfz98ks5tslcJgaJpZM4ToryR.

ghost commented 6 years ago

CMakeOutput.log CMakeError.log

BTW, the error logs are attached.

On 04/26/2018 07:57 PM, Jim wrote:

It fails during the config:

 Run Build Command:"/usr/bin/make" "cmTC_74da5/fast"

  /usr/bin/make -f CMakeFiles/cmTC_74da5.dir/build.make   CMakeFiles/cmTC_74da5.dir/build

  make[1]: Entering directory '/home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++   -std=c++11 -o CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj -c /home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

  Linking CXX executable cmTC_74da5

  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_74da5.dir/link.txt   --verbose=1

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++   -std=c++11 CMakeFiles/cmTC_74da5.dir/testCXXCompiler.cxx.obj -o cmTC_74da5

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o):   In function `exit':

  exit.c:(.text.exit+0x2c): undefined reference to `_exit'

  collect2: error: ld returned 1 exit status

  CMakeFiles/cmTC_74da5.dir/build.make:97: recipe for target 'cmTC_74da5'   failed

  make[1]: *** [cmTC_74da5] Error 1

  make[1]: Leaving directory '/home/jim/AvNet/Quectel/Nucleo-AWS-IoT-mbed/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_74da5/fast' failed

  make: *** [cmTC_74da5/fast] Error 2

  CMake will not be able to correctly generate this project. Call Stack (most recent call first):   CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

On 04/26/2018 07:23 PM, Varun Reddy wrote:

Hi @jflynn129 https://github.com/jflynn129, If you want a static library, when you run make it should build it by default. You will find the library in the |build/archive| as |libaws-iot-sdk-cpp.a|. Which step is it failing at? Does |cmake ../.| fail or does |make| fail? Could you post the output of the build here? Thanks! Varun

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-cpp/issues/97#issuecomment-384818255, or mute the thread https://github.com/notifications/unsubscribe-auth/AR0LLldFUJJ02g3mlm5t7YQy0wUcfz98ks5tslcJgaJpZM4ToryR.

ghost commented 6 years ago

For the sake of compleness, what I have done so far is:

  1. Cloned the repository
  2. created a 'build' directory
  3. updated the 'ToolchainFile.cmake' file to point to my tools 4 went to the 'build' directory and executed 'cmake ../. -DCMAKE_TOOLCHAIN_FILE=../mytools.cmake'

I was under the impression that this would create a bin directory and place the libraries it creates in it.

Maybe I am doing something wrong, but that is how I read the instructions.

shekharhimanshu commented 6 years ago

@jflynn129

I am attempting to build the SDK into a link library (static) for a project, but when I use the steps listed the cmake always fails telling me it can not successfully link (which is no surprise since I am just attempting to build a link library).

The way CMake works is it first checks if the given CXX compiler works or not by trying to compile and link a simple auto generated source file. If that check fails, it abandons further build assuming some problem with the given toolchain.

You can check this inside the CMakeError.log that you attached.

...
Determining if the CXX compiler works failed with the following output:
...
Linking CXX executable cmTC_61328
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_61328.dir/link.txt --verbose=1
/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++       CMakeFiles/cmTC_61328.dir/testCXXCompiler.cxx.obj  -o cmTC_61328 
/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'

...

I noticed you are using arm toolchain for your build and I am guessing it might be missing some settings needed for cross compiling. Could you share your mytools.cmake file?

ghost commented 6 years ago

@shekharhimanshu thank you for the hint, I went back and revisited my flags setting and it got a bit further. I am using mbedtls so I updated the network/CMakeLists.txt.in to:

set(NETWORK_LIBRARY "MbedTLS" CACHE STRING "Network Library to use")

Files: CMakeError.log CMakeOutput.log mytools.cmake.txt

vareddy-zz commented 6 years ago

Hi @jflynn129, The error thrown by CMake seems to be related to the GCC version that you are using. We have a strict dependency on GCC 5 or above as can be seen in the Platform.md, could you check what version the compiler for your platform is? The specific error seems to be related to this stack overflow link. Thanks @shekharhimanshu for pointing the error out. Varun

ghost commented 6 years ago

I'm using:

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc --version ls (GNU coreutils) 8.26 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.

On 04/27/2018 04:26 PM, Varun Reddy wrote:

Hi @jflynn129 https://github.com/jflynn129, The error thrown by CMake seems to be related to the GCC version that you are using. We have a strict dependency on GCC 5 or above as can be seen in the Platform.md https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/Platform.md, could you check what version the compiler for your platform is? The specific error seems to be related to this stack overflow https://stackoverflow.com/questions/19419782/exit-c-text0x18-undefined-reference-to-exit-when-using-arm-none-eabi-gcc link. Thanks @shekharhimanshu https://github.com/shekharhimanshu for pointing the error out. Varun

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-cpp/issues/97#issuecomment-385084933, or mute the thread https://github.com/notifications/unsubscribe-auth/AR0LLh0U88Ns7SWuFSas7_THauoZsThkks5ts379gaJpZM4ToryR.

ghost commented 6 years ago

the other info is: arm-none-eabi-g++ (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

vareddy-zz commented 6 years ago

Hi @jflynn129, The compiler versions are >5 so they should work for the SDK. Were any of the suggestions in the stack overflow link helpful? Thanks! Varun

ghost commented 6 years ago

I was able to get it to build, it was still throwing an error about a reference to pthread_create but it made the library.

ghost commented 6 years ago

ok, I closed this to quickly. I went back and attempted to repeat everything to make sure it worked correctly. What I found is it isn't. The Cmake* output is attached. Using the same compiler specified above (which is >v5). It says it fails on undefined reference to '_exit'. What is interesting, if I simply re-enter the command again, it appears to get a little further each time.

Each time it fails, it reports a link failure. I expect the link step would fail since it is cross-compiling. Can you look at this and let me know what I need to do to get the SDK to successfully generate a successful/correct configure in a cross-compile environment. Previously, I didn't head the failures and simply went ahead and compile the SDK. Because it wasn't configured correctly none of the sample programs to compiled successfully.

The problem appears to be that cmake doesn't operate in a cross-compile environment correctly.

CMakeError.log CMakeOutput.log

vareddy-zz commented 6 years ago

Hi @jflynn129, Could you try compiling with --specs=nosys.specs as stated in the stack overflow link? It seems that the ARM libc's exit() function makes a reference to _exit() which is not defined in any library. Please try that and let me know if that works. Thanks! Varun

ghost commented 6 years ago

That didn't have any effect:

CMakeError.log CMakeOutput.log

but I am not semihosting anyway, just cross-compiling but it was worth a try. I'm not sure why the config tool is trying to link an executable when no executable is required or asked for as would be the case when you are cross-compiling.

vareddy-zz commented 6 years ago

Hi @jflynn129, Are you building on Windows? If yes, this could be a prospective fix. Just need to modify the cross-compile toolchain file to include these changes. The error you are seeing seems more prevalent on Windows from what I see from my research. Thanks! Varun

ghost commented 6 years ago

No I’m building on Ubuntu.

Sent from my iPhone

On May 1, 2018, at 8:22 PM, Varun Reddy notifications@github.com wrote:

Hi @jflynn129, Are you building on Windows? If yes, this could be a prospective fix. Just need to modify the cross-compile toolchain file to include these changes. The error you are seeing seems more prevalent on Windows from what I see from my research. Thanks! Varun

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

shekharhimanshu commented 6 years ago

@jflynn129

I had a look at your mytools.cmake.txt and noticed you told CMake which tools to use for compiling, linking etc. but you never told it where to find the libraries.

Could you try setting, CMAKE_SYSROOT?

set(CMAKE_SYSROOT "/path/to/your/toolchain/root")

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
ghost commented 6 years ago

Nope, didn't make and difference: -- The CXX compiler identification is GNU 7.2.1 -- Check for working CXX compiler: /usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++ -- Check for working CXX compiler: /usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++ -- broken CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message): The C++ compiler "/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++" is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/jflynn/AvNet/Quectel/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_44052/fast"

/usr/bin/make -f CMakeFiles/cmTC_44052.dir/build.make CMakeFiles/cmTC_44052.dir/build

make[1]: Entering directory '/home/jflynn/AvNet/Quectel/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

Building CXX object CMakeFiles/cmTC_44052.dir/testCXXCompiler.cxx.obj

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++ --sysroot=/usr/local/gcc-arm-none-eabi-7-2017-q4-major -o CMakeFiles/cmTC_44052.dir/testCXXCompiler.cxx.obj -c /home/jflynn/AvNet/Quectel/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

Linking CXX executable cmTC_44052

/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_44052.dir/link.txt --verbose=1

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-g++ --sysroot=/usr/local/gcc-arm-none-eabi-7-2017-q4-major CMakeFiles/cmTC_44052.dir/testCXXCompiler.cxx.obj -o cmTC_44052

/usr/local/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':

exit.c:(.text.exit+0x2c): undefined reference to `_exit'

collect2: error: ld returned 1 exit status

CMakeFiles/cmTC_44052.dir/build.make:97: recipe for target 'cmTC_44052' failed

make[1]: *** [cmTC_44052] Error 1

make[1]: Leaving directory '/home/jflynn/AvNet/Quectel/aws-iot-device-sdk-cpp/build/CMakeFiles/CMakeTmp'

Makefile:126: recipe for target 'cmTC_44052/fast' failed

make: *** [cmTC_44052/fast] Error 2

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

It is still simply that cmake is trying to link the program and failing to include all the correct libraries or objects. I think that stdlib is the one that include _exit() I'll try and find that and force it. If that doesn't work, I'll probably just forgo the cmake exercise and manually configure/use the SDK. I didn't want to do that because it breaks the ability to automatically update the SDK and stay insync when new releases come out (and locks anyone that uses my SW solution to use a one-off version of the SDK).

shekharhimanshu commented 6 years ago

Hmm. Not sure what is causing problem here. You can skip the compiler test, CMake does by force settings like below:

include(CMakeForceCompiler)
cmake_force_c_compiler("/path/to/your/c compiler" GNU)
cmake_force_cxx_compiler("/path/to/your/c++ compiler" GNU)

By the way are you able to cross compile and link with your mytools.cmake, a simple C/CXX program? The problem looks to me in your toolchain but I might be wrong.

ghost commented 6 years ago

Fixed, but didn't use cmake. Was probably a self inflicted issue...