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

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

Closed
richmattes opened this issue Jul 19, 2015 · 3 comments
Closed

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

richmattes opened this issue Jul 19, 2015 · 3 comments

Comments

@richmattes
Copy link

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.

@umlaeute
Copy link
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?

@umlaeute
Copy link
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);
        }

@richmattes
Copy link
Author

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

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

No branches or pull requests

2 participants