Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

CMake failure when building for arm platform #118

Closed
GrantEdwards opened this issue Feb 3, 2017 · 9 comments
Closed

CMake failure when building for arm platform #118

GrantEdwards opened this issue Feb 3, 2017 · 9 comments
Assignees

Comments

@GrantEdwards
Copy link

GrantEdwards commented Feb 3, 2017

I'm trying to build the SDK on a Linux AMD64 host for an ARM9 target,
and I keep getting a configuration failure for azure_c_shared_utility,
and I'm unable to determine what's wrong

$ ./tools/build.sh --toolchain-file ../Toolchain-arm-linux.cmake
~/azure/azure-iot-gateway-sdk/build ~/azure/azure-iot-gateway-sdk
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /home/nextgen/toolchain/bin/arm-linux-gcc
-- Check for working C compiler: /home/nextgen/toolchain/bin/arm-linux-gcc -- 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: /home/nextgen/toolchain/bin/arm-linux-g++
[...]
-- AIG architecture: ARM
-- azure_c_shared_utility not found...
-- Building azure_c_shared_utility...
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /home/nextgen/toolchain/bin/arm-linux-gcc
-- Check for working C compiler: /home/nextgen/toolchain/bin/arm-linux-gcc -- 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: /home/nextgen/toolchain/bin/arm-linux-g++
-- Check for working CXX compiler: /home/nextgen/toolchain/bin/arm-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /home/nextgen/buildroot/output/host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/usr/lib64/libssl.so;/home/nextgen/buildroot/output/host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/usr/lib64/libcrypto.so (found version "1.0.0g") 
-- Shared_Util architecture: ARM
-- iothub architecture: ARM
-- Configuring done
-- Generating done
-- Build files have been written to: /home/grante/azure/azure-iot-gateway-sdk/deps/c-utility/build
-- Installing azure_c_shared_utility. Please wait...
CMake Error at gatewayFunctions.cmake:169 (message):
  Error installing azure_c_shared_utility: 2
Call Stack (most recent call first):
  dependencies.cmake:13 (findAndInstall)
  CMakeLists.txt:186 (include)


-- Configuring incomplete, errors occurred!
See also "/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeOutput.log".
See also "/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeError.log".

Looking at the CMake log files, I see:

CMakeError.log:

Determining if the __x86_64__ exist failed with the following output:
Change Dir: /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_fdc38/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_fdc38.dir/build.make CMakeFiles/cmTC_fdc38.dir/build
gmake[1]: Entering directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_fdc38.dir/CheckSymbolExists.c.o
/home/nextgen/toolchain/bin/arm-linux-gcc     -o CMakeFiles/cmTC_fdc38.dir/CheckSymbolExists.c.o   -c /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function 'main':
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:7:19: error: '__x86_64__' undeclared (first use in this function)
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:7:19: note: each undeclared identifier is reported only once for each function it appears in
gmake[1]: *** [CMakeFiles/cmTC_fdc38.dir/build.make:66: CMakeFiles/cmTC_fdc38.dir/CheckSymbolExists.c.o] Error 1
gmake[1]: Leaving directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:126: cmTC_fdc38/fast] Error 2

File /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */

int main(int argc, char** argv)
{
  (void)argv;
#ifndef __x86_64__
  return ((int*)(&__x86_64__))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the __i386__ exist failed with the following output:
Change Dir: /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_3de9c/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_3de9c.dir/build.make CMakeFiles/cmTC_3de9c.dir/build
gmake[1]: Entering directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_3de9c.dir/CheckSymbolExists.c.o
/home/nextgen/toolchain/bin/arm-linux-gcc     -o CMakeFiles/cmTC_3de9c.dir/CheckSymbolExists.c.o   -c /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function 'main':
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:7:19: error: '__i386__' undeclared (first use in this function)
/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:7:19: note: each undeclared identifier is reported only once for each function it appears in
gmake[1]: *** [CMakeFiles/cmTC_3de9c.dir/build.make:66: CMakeFiles/cmTC_3de9c.dir/CheckSymbolExists.c.o] Error 1
gmake[1]: Leaving directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:126: cmTC_3de9c/fast] Error 2

File /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */

int main(int argc, char** argv)
{
  (void)argv;
#ifndef __i386__
  return ((int*)(&__i386__))[argc];
#else
  (void)argc;
  return 0;
#endif
}

CMakeOutput.log:

The target system is: Linux - 1 - 
The host system is: Linux - 4.4.39-gentoo - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /home/nextgen/toolchain/bin/arm-linux-gcc 
Build flags: 
Id flags: 

The output was:
0
[...]
Feature record: CXX_FEATURE:0cxx_unrestricted_unions
Feature record: CXX_FEATURE:0cxx_user_literals
Feature record: CXX_FEATURE:0cxx_variable_templates
Feature record: CXX_FEATURE:0cxx_variadic_macros
    Feature record: CXX_FEATURE:0cxx_variadic_templates
Determining if the __arm__ exist passed with the following output:
Change Dir: /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_d2eb9/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_d2eb9.dir/build.make CMakeFiles/cmTC_d2eb9.dir/build
gmake[1]: Entering directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d2eb9.dir/CheckSymbolExists.c.o
/home/nextgen/toolchain/bin/arm-linux-gcc     -o CMakeFiles/cmTC_d2eb9.dir/CheckSymbolExists.c.o   -c /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_d2eb9
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d2eb9.dir/link.txt --verbose=1
/home/nextgen/toolchain/bin/arm-linux-gcc       CMakeFiles/cmTC_d2eb9.dir/CheckSymbolExists.c.o  -o cmTC_d2eb9 -rdynamic 
gmake[1]: Leaving directory '/home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp'

File /home/grante/azure/azure-iot-gateway-sdk/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */

int main(int argc, char** argv)
{
  (void)argv;
#ifndef __arm__
  return ((int*)(&__arm__))[argc];
#else
  (void)argc;
  return 0;
#endif
}
@GrantEdwards
Copy link
Author

The error is caused by a missing include file uuid/uuid.h. It appears that the gateway SDK
is intended for full-up Linux systems rather than small embedded systems?

I would suggest this implementation for UniqueId_Generate(). It's much more portable and
requires minimal library support. Warning: I haven't been able to test it yet, since I still can't
get the SDK to build for my ARM target due to other unresolved library requirements.

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "azure_c_shared_utility/uniqueid.h"
#include "azure_c_shared_utility/xlogging.h"

DEFINE_ENUM_STRINGS(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES);

UNIQUEID_RESULT UniqueId_Generate(char* uid, size_t len)
{
    UNIQUEID_RESULT result;

    /* Codes_SRS_UNIQUEID_07_002: [If uid is NULL then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
    /* Codes_SRS_UNIQUEID_07_003: [If len is less then 37 then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
    if (uid == NULL || len < 37)
    {
        result = UNIQUEID_INVALID_ARG;
        LogError("Buffer Size is Null. (result = %s)", ENUM_TO_STRING(UNIQUEID_RESULT, result));
    }
    else
    {
        int fd = open("/proc/sys/kernel/random/uuid",O_RDONLY);
        if (fd < 0)
          result = UNIQUEID_ERROR;
        else
          {
            memset(uid, 0, len);
            if (len-1 == read(fd,uid,len-1))
              result = UNIQUEID_OK;
            else
              result = UNIQUEID_ERROR;
            close(fd);
          }
    }
    return result;
}

@damonbarry
Copy link
Member

@GrantEdwards How does your suggested code above fix the #include error?

If you could attach two files from your build it would help us narrow down the problem:
deps/c-utility/build/error.txt
deps/c-utility/build/output.txt

@GrantEdwards
Copy link
Author

How does your suggested code above fix the #include error?

It doesn't include <uuid/uuid.h>.

Nor does it need the uuid library at link time. [That requires a
different fix to remove the -luuid from the link command.]

If you could attach two files from your build it would help us
narrow down the problem.

As I mentioned above: the error is caused by a missing include file
uuid/uuid.h

My platform doesn't have libuuid or uuid/uuid.h. The uuid library is
part of util-linux. Util-linux is itself quite large, and it pulls in
some other heavyweight platform requirements (such as wchar support).

@damonbarry
Copy link
Member

In the azure-c-shared-utility repo, we already provide a CMake option called use_default_uuid. If you set this when you build azure-c-shared-utility, then we build a cross-platform version of UniqueId_Generate which doesn't require uuid/uuid.h. That solves the problem you're seeing.

That said, the gateway SDK build system does not honor this option--we don't pass it down to azure-c-shared-utility when we build it for you. I'll use this issue as an opportunity to fix that.

@damonbarry
Copy link
Member

I added an option to CMake, now I need to expose it through our build script...

@damonbarry
Copy link
Member

Should be ready to go now... @GrantEdwards please give it a try!

@damonbarry
Copy link
Member

Fix is in the 2017-03-06 release.

@darobs
Copy link
Contributor

darobs commented Aug 2, 2017

The first place to look would be in the deps/ctest/build subdirectory in the repository - this is where the Edge builds the ctest library. There should be an output.txt and error.txt in there which should help us figure out the problem.

It's unusual for ctest to fail to build - the usual problem is the submodule has not been initialized, but that should happen during the build if the CMake can detect the submodule is not present. It wouldn't hurt to do:

git submodule update --init --recursive

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants
@GrantEdwards @damonbarry @darobs and others