openbmc / phosphor-logging

Libraries for common event and logging creation.
Apache License 2.0
14 stars 34 forks source link

Build failed with gcc/g++ version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) #31

Closed vigneshs88 closed 1 year ago

vigneshs88 commented 1 year ago

Hi Folks,

Build failed with gcc/g++ version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20.

But I could not figure out where to give the flag. Please help to build.

msgubuntu@msgubuntu-OptiPlex-5000:~/vignesh/dbus/phosphor-logging$ ninja -C builddir ninja: Entering directory `builddir' [3/880] Compiling C++ object subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_event.cpp.o FAILED: subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_event.cpp.o c++ -Isubprojects/sdbusplus/libsdbusplus.so.1.0.0.p -Isubprojects/sdbusplus -I../subprojects/sdbusplus -I../subprojects/sdbusplus/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -Werror -std=c++2a -O2 -g -fPIC -MD -MQ subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_event.cpp.o -MF subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_event.cpp.o.d -o subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_event.cpp.o -c ../subprojects/sdbusplus/src/event.cpp ../subprojects/sdbusplus/src/event.cpp: In member function ‘sdbusplus::event::source sdbusplus::event::event::add_oneshot_timer(sd_event_time_handler_t, void, sdbusplus::event::event::time_resolution, sdbusplus::event::event::time_resolution)’: ../subprojects/sdbusplus/src/event.cpp:156:15: error: ‘sd_event_add_time_relative’ was not declared in this scope; did you mean ‘sd_event_add_time’? 156 | auto rc = sd_event_add_time_relative(eventp, &s.sourcep, CLOCK_BOOTTIME, | ^~~~~~ | sd_event_add_time [7/880] Compiling C++ object subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_bus.cpp.o FAILED: subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_bus.cpp.o c++ -Isubprojects/sdbusplus/libsdbusplus.so.1.0.0.p -Isubprojects/sdbusplus -I../subprojects/sdbusplus -I../subprojects/sdbusplus/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -Werror -std=c++2a -O2 -g -fPIC -MD -MQ subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_bus.cpp.o -MF subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_bus.cpp.o.d -o subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_bus.cpp.o -c ../subprojects/sdbusplus/src/bus.cpp In file included from ../subprojects/sdbusplus/include/sdbusplus/message.hpp:6, from ../subprojects/sdbusplus/include/sdbusplus/bus.hpp:7, from ../subprojects/sdbusplus/src/bus.cpp:1: ../subprojects/sdbusplus/include/sdbusplus/message/append.hpp: In static member function ‘static void sdbusplus::message::details::append_single<std::basic_string_view >::op(sdbusplus::SdBusInterface, sd_bus_message, T&&)’: ../subprojects/sdbusplus/include/sdbusplus/message/append.hpp:225:24: error: ‘bit_cast’ is not a member of ‘std’; did you mean ‘bad_cast’? 225 | iovec iov{std::bit_cast<void>(s.data()), s.size()}; | ^~~~ | bad_cast ../subprojects/sdbusplus/include/sdbusplus/message/append.hpp:225:33: error: expected primary-expression before ‘void’ 225 | iovec iov{std::bit_cast<void*>(s.data()), s.size()}; | ^~~~ ../subprojects/sdbusplus/include/sdbusplus/message/append.hpp:225:33: error: expected ‘}’ before ‘void’ ../subprojects/sdbusplus/include/sdbusplus/message/append.hpp:225:33: error: expected ‘,’ or ‘;’ before ‘void’ [8/880] Compiling C++ object subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_server_interface.cpp.o FAILED: subprojects/sdbusplus/libsdbusplus.so.1.0.0.p/src_server_interface.cpp.o

Regards, Vignesh

williamspatrick commented 1 year ago

You will need GCC 12 at a minimum but 13 is better. There was a lot of C++20 function missing from GCC 9, including some of the constexpr string support failing here.

williamspatrick commented 1 year ago

Your systemd library is also too old. Notice the missing API.

vigneshs88 commented 1 year ago

Hi William,

Thank you for the quick response. Understood, we need minimum gcc 12.

But, we have a specific requirement. ls there any possibility to compile using gcc-10.2.1(using some trick)? Anyone tried it?

Regards, Vignesh

eduvfalc commented 7 months ago

I am also getting errors when building with gcc 12.3. I wonder if the package versions required to build the project would not be better placed somewhere in the README. It would salve people time in configuring the right setup for it.

williamspatrick commented 7 months ago

We don't really expect anyone to be building any of the OpenBMC packages outside of either the CI docker container or Yocto (unless they know what they are doing). Both of those specify a compiler version.

We need GCC-13 or greater for almost all of the code repositories due to C++23 support only available there.

What are you trying to accomplish with this library outside of those environments l?

eduvfalc commented 7 months ago

Clear. Thank you for the quick response! My goal was to add the lg2 logger to a non-Yocto project, but I understand now that the right way to do so is to add my component to the Yocto build which contains the OpenBMC packages.

williamspatrick commented 7 months ago

My goal was to add the lg2 logger to a non-Yocto project, but I understand now that the right way to do so is to add my component to the Yocto build which contains the OpenBMC packages.

You're the first person who has asked to do that. If it is something useful we can figure out how to better specify the dependencies and/or give an option to build lg2 on its own. Feel free to let us know what would be most helpful.

lg2 itself probably doesn't have strong requirements to use GCC-13, but the phosphor-logging repository uses sdbusplus which does. If we were to find a way to split out the parts you are most interested in we could probably relax the compiler requirements.