Skip to content

Assimp 3.1.1 fails to build on big-endian architecture #613

Closed

Description

@richmattes

I'm trying to build assimp-3.1.1 on the redhat 7 ppc64 architecture. I'm getting the following error:

/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp: In instantiation of 'std::size_t Assimp::Copy(uint8_t*, T&) [with T = short unsigned int; std::size_t = long unsigned int; uint8_t = unsigned char]':
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:93:44:   required from here
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:85:21: error: lvalue required as unary '&' operand
   std::memcpy(data, &AI_BE(field), sizeof(field)); return sizeof(field);
                     ^
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp: In instantiation of 'std::size_t Assimp::Copy(uint8_t*, T&) [with T = unsigned int; std::size_t = long unsigned int; uint8_t = unsigned char]':
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:94:44:   required from here
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:85:21: error: lvalue required as unary '&' operand
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp: In instantiation of 'std::size_t Assimp::Copy(uint8_t*, T&) [with T = int; std::size_t = long unsigned int; uint8_t = unsigned char]':
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:108:42:   required from here
/builddir/build/BUILD/assimp-3.1.1/code/Bitmap.cpp:85:21: error: lvalue required as unary '&' operand
make[2]: *** [code/CMakeFiles/assimp.dir/Bitmap.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

Full build log is here.

It looks like the source of this issue is the in-line use of the AI_BE(t) macro, which on big-endian architectures expands to ByteSwap::Swapped(t). Trying to pass a reference to the expanded statement to memcpy fails with the above error.

I was able to work around the issue by modifying the Copy function in Bitmap.cpp to create a temporary variable that holds the result of AI_BE, and then passing the temporary variable to memcpy.

Activity

  1. umlaeute commented on Aug 10, 2015

    @umlaeute
    Contributor

    I can confirm the issue (now that i finally got around at packaging assimp-3.1.1 for Debian).

    @jpgr87 could you share your workaround?

  2. umlaeute commented on Aug 10, 2015

    @umlaeute
    Contributor

    probably something like:

            template<typename T>
            inline std::size_t Copy(uint8_t* data, T& field) {
    #ifdef AI_BUILD_BIG_ENDIAN
                    T field_swapped=AI_BE(field);
                    std::memcpy(data, &field_swapped, sizeof(field)); return sizeof(field);
    #else
                    std::memcpy(data, &AI_BE(field), sizeof(field)); return sizeof(field);
    #endif /* AI_BUILD_BIG_ENDIAN */
            }

    or even simpler:

            template<typename T>
            inline std::size_t Copy(uint8_t* data, T& field) {
                    T field_=AI_BE(field);
                    std::memcpy(data, &field_, sizeof(field)); return sizeof(field);
            }
  3. richmattes commented on Aug 10, 2015

    @richmattes
    Author

    My fix is nearly identical to your "even simpler" approach. The patch I'm using can be found here

  4. added a commit that references this issue on Nov 13, 2015
  5. added
    Build
    Bug
    on Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBuild

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions