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

fatal error: 'boost/predef/other/endian.h' file not found with MSGPACK_USE_BOOST OFF #1025

Closed
leocencetti opened this issue Jun 13, 2022 · 14 comments

Comments

@leocencetti
Copy link

leocencetti commented Jun 13, 2022

Similar to #1005, there seems to be a dependency on boost/predef/other/endian.h when building with MSGPACK_USE_BOOST=OFF.

I have reproduced this issue on both Linux and Windows.

Minimal reproducible example: https://github.com/leocencetti/msgpack-c-issue-1025-example

(base)leonardo@T14-LC:~/Software/comm-protocol$ cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DMSGPACK_USE_BOOST=OFF
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is Clang 14.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Doxygen: /usr/bin/doxygen (found version "1.9.1") found components: doxygen missing components: dot
-- Found Python: /usr/bin/python3.10 (found version "3.10.4") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/leonardo/Software/comm-protocol/build
(base) leonardo@T14-LC:~/Software/comm-protocol$ cmake --build build
[1/15] Building CXX object comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolSensorDef.cpp.o
FAILED: comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolSensorDef.cpp.o 
/usr/bin/c++  -I/home/leonardo/Software/comm-protocol/comm_protocol/include -I"/home/leonardo/Software/comm-protocol/comm_protocol/\$<BUILD_INTERFACE:/home/leonardo/Software/comm-protocol/comm_protocol/include" -I/home/leonardo/Software/comm-protocol/build/comm_protocol -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-build/include -O3 -DNDEBUG -MD -MT comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolSensorDef.cpp.o -MF comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolSensorDef.cpp.o.d -o comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolSensorDef.cpp.o -c /home/leonardo/Software/comm-protocol/comm_protocol/src/commProtocolSensorDef.cpp
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/src/commProtocolSensorDef.cpp:11:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolSensorDef.h:15:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack.hpp:10:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack_decl.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/pack_decl.hpp:15:
/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/sysdep.hpp:102:10: fatal error: 'boost/predef/other/endian.h' file not found
#include <boost/predef/other/endian.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[2/15] Building CXX object comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolHandle.cpp.o
FAILED: comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolHandle.cpp.o 
/usr/bin/c++  -I/home/leonardo/Software/comm-protocol/comm_protocol/include -I"/home/leonardo/Software/comm-protocol/comm_protocol/\$<BUILD_INTERFACE:/home/leonardo/Software/comm-protocol/comm_protocol/include" -I/home/leonardo/Software/comm-protocol/build/comm_protocol -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-build/include -O3 -DNDEBUG -MD -MT comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolHandle.cpp.o -MF comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolHandle.cpp.o.d -o comm_protocol/CMakeFiles/comm_protocol.dir/src/commProtocolHandle.cpp.o -c /home/leonardo/Software/comm-protocol/comm_protocol/src/commProtocolHandle.cpp
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/src/commProtocolHandle.cpp:12:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolHandle.h:15:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolSensorDef.h:15:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack.hpp:10:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack_decl.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/pack_decl.hpp:15:
/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/sysdep.hpp:102:10: fatal error: 'boost/predef/other/endian.h' file not found
#include <boost/predef/other/endian.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[4/15] Building CXX object comm_protocol/tests/unit/CMakeFiles/test_sensor_def.dir/test_sensor_def.cpp.o
FAILED: comm_protocol/tests/unit/CMakeFiles/test_sensor_def.dir/test_sensor_def.cpp.o 
/usr/bin/c++  -I/home/leonardo/Software/comm-protocol/comm_protocol/include -I"/home/leonardo/Software/comm-protocol/comm_protocol/\$<BUILD_INTERFACE:/home/leonardo/Software/comm-protocol/comm_protocol/include" -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-build/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googletest/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googletest -O3 -DNDEBUG -MD -MT comm_protocol/tests/unit/CMakeFiles/test_sensor_def.dir/test_sensor_def.cpp.o -MF comm_protocol/tests/unit/CMakeFiles/test_sensor_def.dir/test_sensor_def.cpp.o.d -o comm_protocol/tests/unit/CMakeFiles/test_sensor_def.dir/test_sensor_def.cpp.o -c /home/leonardo/Software/comm-protocol/comm_protocol/tests/unit/test_sensor_def.cpp
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/tests/unit/test_sensor_def.cpp:3:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolSensorDef.h:15:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack.hpp:10:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack_decl.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/pack_decl.hpp:15:
/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/sysdep.hpp:102:10: fatal error: 'boost/predef/other/endian.h' file not found
#include <boost/predef/other/endian.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[6/15] Building CXX object comm_protocol/tests/unit/CMakeFiles/test_comm_protocol_handle.dir/test_comm_protocol_handle.cpp.o
FAILED: comm_protocol/tests/unit/CMakeFiles/test_comm_protocol_handle.dir/test_comm_protocol_handle.cpp.o 
/usr/bin/c++  -I/home/leonardo/Software/comm-protocol/comm_protocol/include -I"/home/leonardo/Software/comm-protocol/comm_protocol/\$<BUILD_INTERFACE:/home/leonardo/Software/comm-protocol/comm_protocol/include" -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include -I/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-build/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googletest/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googletest -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googlemock/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/googlemock -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src/include -isystem /home/leonardo/Software/comm-protocol/build/_deps/gtest-src -O3 -DNDEBUG -MD -MT comm_protocol/tests/unit/CMakeFiles/test_comm_protocol_handle.dir/test_comm_protocol_handle.cpp.o -MF comm_protocol/tests/unit/CMakeFiles/test_comm_protocol_handle.dir/test_comm_protocol_handle.cpp.o.d -o comm_protocol/tests/unit/CMakeFiles/test_comm_protocol_handle.dir/test_comm_protocol_handle.cpp.o -c /home/leonardo/Software/comm-protocol/comm_protocol/tests/unit/test_comm_protocol_handle.cpp
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/tests/unit/test_comm_protocol_handle.cpp:7:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolHandle.h:15:
In file included from /home/leonardo/Software/comm-protocol/comm_protocol/include/comm_protocol/commProtocolSensorDef.h:15:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack.hpp:10:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/object_decl.hpp:14:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/pack_decl.hpp:13:
In file included from /home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/v1/pack_decl.hpp:15:
/home/leonardo/Software/comm-protocol/build/_deps/msgpackc-src/include/msgpack/sysdep.hpp:102:10: fatal error: 'boost/predef/other/endian.h' file not found
#include <boost/predef/other/endian.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[8/15] Building CXX object _deps/gtest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
ninja: build stopped: subcommand failed.
@leocencetti
Copy link
Author

leocencetti commented Jun 13, 2022

Digging a bit into the code, it seems that the MSGPACK_NO_BOOST symbol is not defined (the various if defined(MSGPACK_NO_BOOST) evaluate to false): this leads to the inclusion of multiple boost headers.

CMakeLists.txt#L79 is hit as expected.

@leocencetti
Copy link
Author

Looking at the verbose output of cmake --build build, it seems that all CMAKE_CXX_FLAGS are lost somewhere (or overwritten).

Adding this after CMakeLists.txt#L113 fixes the missing definition:

TARGET_COMPILE_DEFINITIONS(msgpackc-cxx INTERFACE MSGPACK_NO_BOOST) # possibly add other flags as well

@redboltz
Copy link
Contributor

I checked CMakeLists.txt but I couldn't find the problem. All CMAKE_CXX_FLAGS preserved at all places.

TARGET_COMPILE_DEFINITIONS(msgpackc-cxx INTERFACE MSGPACK_NO_BOOST) # possibly add other flags as well

msgpack-c should depend on boost by default. So I think that this modification is not good.

I couldn't reproduce the error. Maybe https://stackoverflow.com/help/minimal-reproducible-example is helpful.

I'm not expert of cmake. If you would find the good solution, please send a pull request.

@leocencetti
Copy link
Author

Hi @redboltz, thank you for your reply. It does not fail as long as you have libboost installed on your system.

I've put together a small example that successfully reproduces the issue on our systems:
https://github.com/leocencetti/msgpack-c-issue-1025-example

@leocencetti
Copy link
Author

msgpack-c should depend on boost by default. So I think that this modification is not good

Indeed it wasn't meant as a solution, but rather as a way of showing that the MSGPACK_NO_BOOST symbol is not defined as expected.

@buip
Copy link

buip commented Aug 3, 2022

same for me

@redboltz
Copy link
Contributor

redboltz commented Aug 3, 2022

cmake -DCMAKE_CXX_FLAGS="-DMSGPACK_NO_BOOST"

could be workaround.

Essential fix is not yet.

@redboltz
Copy link
Contributor

redboltz commented Aug 3, 2022

According to the cmake document https://cmake.org/cmake/help/latest/command/add_library.html

add_library is defined as follows in up to date spec:

add_library(<name> INTERFACE [<source>...] [EXCLUDE_FROM_ALL])

I read the doucment but I didn't understand how it works.

Should the following line

TARGET_COMPILE_DEFINITIONS(msgpackc-cxx INTERFACE)

be

TARGET_COMPILE_DEFINITIONS(msgpackc-cxx MSGPACK_CXX11  MSGPACK_CXX14 MSGPACK_CXX17 ...   MSGPACK_USE_BOOST ...)

?

What does parameters followed by INTERFACE mean?
[<source>...] ?

msgpack-c cmake minimum requirement is v3.1

CMAKE_MINIMUM_REQUIRED (VERSION 3.1 FATAL_ERROR)

v3.1add_library definition is something different
https://cmake.org/cmake/help/v3.1/command/add_library.html

add_library(<name> INTERFACE [IMPORTED [GLOBAL]])

I got confused.

@redboltz
Copy link
Contributor

redboltz commented Aug 3, 2022

TARGET_COMPILE_DEFINITIONS(msgpackc-cxx MSGPACK_CXX11  MSGPACK_CXX14 MSGPACK_CXX17 ...   MSGPACK_USE_BOOST ...)

This is wrong. I wrote cmake options as arguments. In @leocencetti example, it is C++ compiler option (macro definition by -D option). I got confuse more. I couldn't find corresponding document in cmake add_library manual...

@redboltz
Copy link
Contributor

redboltz commented Aug 3, 2022

Little by little, I'm understanding the essential issue.

The issue is:

How to reflect cmake sub project's compiler options to the parent cmake project.

@redboltz
Copy link
Contributor

redboltz commented Aug 3, 2022

How to reflect cmake sub project's compiler options to the parent cmake project.

I studied about that. I couldn't find a good way to do that.

In order to modify msgpack-c option, you need to define configuration macro as C++ compiler options instead of cmake options.
The list of configuration macro is https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_configure
(I updated)

So in this case, removing boost dependency, is cmake -DCMAKE_CXX_FLAGS="-DMSGPACK_NO_BOOST".
(-DCMAKE_USE_BOOST=OFF is not requred. )

This is my current conclusion.

If there is a proper way to reflect cmake sub project's configured C++ compiler flags to the parent project, please let me know.

@redboltz
Copy link
Contributor

redboltz commented Aug 5, 2022

I asked this question to stackoverflow and got the answer.
https://stackoverflow.com/questions/73229948/how-to-propagate-sub-projects-conditional-macro-definitions-to-parent-project/73240728#73240728
I just glanced the answer but I think that conditional reflection to the parent project can possible!
I will try applying this approach to msgpack-c this weekend :)

redboltz added a commit that referenced this issue Aug 6, 2022
Propagate compiler options that are decided by cmake options to the
parent project.
redboltz added a commit to redboltz/msgpack-c that referenced this issue Aug 6, 2022
Propagate compiler options that are decided by cmake options to the
parent project.
redboltz added a commit to redboltz/msgpack-c that referenced this issue Aug 6, 2022
Propagate compiler options that are decided by cmake options to the
parent project.
redboltz added a commit to redboltz/msgpack-c that referenced this issue Aug 6, 2022
Propagate compiler options that are decided by cmake options to the
parent project.
redboltz added a commit to redboltz/msgpack-c that referenced this issue Aug 6, 2022
Propagate compiler options that are decided by cmake options to the
parent project.
@redboltz
Copy link
Contributor

redboltz commented Aug 6, 2022

Finally, I implemented #1028
Could you try this?

redboltz added a commit that referenced this issue Aug 19, 2022
@redboltz
Copy link
Contributor

Fixed by #1028

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

3 participants