p4c
p4c copied to clipboard
build failed in centos7
I try to build on centos, but failed with the following message. I want to know if there is a way to solve the problem? Thanks a lot!
In file included from /home/hunter/P4/p4c/build/lib/unified_libp4ctoolkit_srcs_1.cpp:2:0:
/home/hunter/P4/p4c/lib/backtrace.cpp:71:56: error: ‘void std::__throw_out_of_range_fmt(const char*, ...)’ should have been declared inside ‘std’
void std::__throw_out_of_range_fmt(char const *fmt, ...) {
^
/home/hunter/P4/p4c/lib/backtrace.cpp: In function ‘void std::__throw_system_error(int)’:
/home/hunter/P4/p4c/lib/backtrace.cpp:85:31: error: ‘system_error’ is not a member of ‘std’
throw backtrace_exception<std::system_error>(error_code(err, generic_category()));
^
/home/hunter/P4/p4c/lib/backtrace.cpp:85:31: error: ‘system_error’ is not a member of ‘std’
/home/hunter/P4/p4c/lib/backtrace.cpp:85:48: error: template argument 1 is invalid
throw backtrace_exception<std::system_error>(error_code(err, generic_category()));
^
/home/hunter/P4/p4c/lib/backtrace.cpp:85:83: error: ‘generic_category’ was not declared in this scope
throw backtrace_exception<std::system_error>(error_code(err, generic_category()));
^
/home/hunter/P4/p4c/lib/backtrace.cpp:85:84: error: ‘error_code’ was not declared in this scope
throw backtrace_exception<std::system_error>(error_code(err, generic_category()));
^
It may be worth to check out this discussion #2698. backtrace.cpp and gc.cpp are not very portable, sadly.
While https://github.com/p4lang/p4c/pull/2924 will get you past that, you will run into other issues later in the compilation. It looks like you are using the default compiler for centos7, gcc 4.8 (correct me if I'm wrong). The C++11 regex implementation is broken in gcc 4.8 if I recall correctly, and as indicated in the README, p4c requires gcc 4.9 or greater. If you can install a more recent gcc version, it should resolve your issue.
While #2924 will get you past that, you will run into other issues later in the compilation. It looks like you are using the default compiler for centos7, gcc 4.8 (correct me if I'm wrong). The C++11 regex implementation is broken in gcc 4.8 if I recall correctly, and as indicated in the README, p4c requires gcc 4.9 or greater. If you can install a more recent gcc version, it should resolve your issue.
I tried with gcc 9.3.1, it returns the following error:
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld.gold: error: /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++_nonshared.a(regex48.o): multiple definition of 'std::__throw_regex_error(std::regex_constants::error_type)'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld.gold: ../../lib/libp4ctoolkit.a(unified_libp4ctoolkit_srcs_1.cpp.o): previous definition here
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld.gold: error: /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++_nonshared.a(system_error48.o): multiple definition of 'std::__throw_system_error(int)'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld.gold: ../../lib/libp4ctoolkit.a(unified_libp4ctoolkit_srcs_1.cpp.o): previous definition here
collect2: error: ld returned 1 exit status
make[2]: *** [tools/ir-generator/CMakeFiles/irgenerator.dir/build.make:130: tools/ir-generator/irgenerator] Error 1
make[1]: *** [CMakeFiles/Makefile2:1087: tools/ir-generator/CMakeFiles/irgenerator.dir/all] Error 2
Not sure why you are seeing this error, maybe because you are using a static version of libstdc++, which is not something we test for. If you just need to build p4c, and using a shared version of libstdc++ is not an option for you, you can try to make all these symbols weak: https://github.com/p4lang/p4c/blob/main/lib/backtrace.cpp#L37-L88. You can also delete that code altogether and you should be able to get a p4c binary.
Not sure why you are seeing this error, maybe because you are using a static version of libstdc++, which is not something we test for. If you just need to build p4c, and using a shared version of libstdc++ is not an option for you, you can try to make all these symbols weak: https://github.com/p4lang/p4c/blob/main/lib/backtrace.cpp#L37-L88. You can also delete that code altogether and you should be able to get a p4c binary.
Thanks a lot, that works for this problem, but the new problem comes:
In file included from /home/hunter/P4/p4c/build/frontends/unified_frontend_sources_6.cpp:6:0:
/home/hunter/P4/p4c/frontends/p4/strengthReduction.cpp: In member function ‘int P4::DoStrengthReduction::isPowerOf2(const IR::Expression*) const’:
/home/hunter/P4/p4c/frontends/p4/strengthReduction.cpp:61:39: error: ‘msb’ is not a member of ‘boost::multiprecision’
auto log = boost::multiprecision::msb(cst->value);
^~~
/home/hunter/P4/p4c/frontends/p4/strengthReduction.cpp:61:39: note: suggested alternative: ‘lsb’
auto log = boost::multiprecision::msb(cst->value);
^~~
lsb
make[2]: *** [frontends/CMakeFiles/frontend.dir/build.make:250: frontends/CMakeFiles/frontend.dir/unified_frontend_sources_6.cpp.o] Error 1
It seems that the boost::multiprecision doesn't have the member. Is it a problem about version mismatch?
@hunterzju Is it reasonable to close this issue now? i.e. was the question answered to your satisfaction?