pavel-odintsov / fastnetmon

FastNetMon - very fast DDoS sensor with sFlow/Netflow/IPFIX/SPAN support
https://fastnetmon.com
GNU General Public License v2.0
3.44k stars 568 forks source link

Prioritize find_package config mode for Protobuf #997

Closed cho-m closed 9 months ago

cho-m commented 11 months ago

This sets correct C++ standard for newer Protobuf installations as FindProtobuf module only sets cxx_std_11


Otherwise, since CMAKE_CXX_STANDARD is not forced, the build will default to -std=gnu++11, e.g.

[ 41%] Building CXX object CMakeFiles/attribute_pb_cc.dir/gobgp_client/attribute.pb.cc.o
/opt/homebrew/Library/Homebrew/shims/mac/super/clang++ -DDECLARE_FAKE_BPF_LINK_TYPE -DDECLARE_FAKE_BPF_STATS -DENABLE_CAPNP -DENABLE_GOBGP -DENABLE_PCAP -DFASTNETMON_API -DMONGO -DREDIS -I/opt/fastnetmon-community/libraries/abseil_2022_06_23/include -I/opt/fastnetmon-community/libraries/capnproto_0_8_0/include -I/opt/homebrew/include/libmongoc-1.0 -I/opt/homebrew/include/libbson-1.0 --std=c++20 -O3 -DNDEBUG -std=gnu++11 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk   -Wreorder -Wunused -Wparentheses -Wimplicit-fallthrough -Wreturn-type -Wuninitialized -Winit-self -Wmaybe-uninitialized -Wcatch-value=3 -Wclass-memaccess -MD -MT CMakeFiles/attribute_pb_cc.dir/gobgp_client/attribute.pb.cc.o -MF CMakeFiles/attribute_pb_cc.dir/gobgp_client/attribute.pb.cc.o.d -o CMakeFiles/attribute_pb_cc.dir/gobgp_client/attribute.pb.cc.o -c /tmp/fastnetmon-20231226-82930-1elr23/fastnetmon-1.2.6/src/gobgp_client/attribute.pb.cc

Which then results in build failure:

In file included from /tmp/fastnetmon-20231226-82930-1elr23/fastnetmon-1.2.6/src/gobgp_client/attribute.pb.cc:4:
In file included from /tmp/fastnetmon-20231226-82930-1elr23/fastnetmon-1.2.6/src/gobgp_client/attribute.pb.h:13:
In file included from /opt/homebrew/include/google/protobuf/port_def.inc:33:
In file included from /opt/homebrew/include/absl/base/attributes.h:37:
In file included from /opt/homebrew/include/absl/base/config.h:86:
/opt/homebrew/include/absl/base/policy_checks.h:79:2: error: "C++ versions less than C++14 are not supported."
#error "C++ versions less than C++14 are not supported."
 ^

On side note, forcing -DCMAKE_CXX_STANDARD=20 will get past above failure and then fail if Protobuf is linked to Abseil:

[ 81%] Linking CXX executable fastnetmon_api_client
/opt/homebrew/Cellar/cmake/3.28.1/bin/cmake -E cmake_link_script CMakeFiles/fastnetmon_api_client.dir/link.txt --verbose=1
/opt/homebrew/Library/Homebrew/shims/mac/super/clang++  --std=c++20 -O3 -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/fastnetmon_api_client.dir/fastnetmon_api_client.cpp.o -o fastnetmon_api_client  /opt/homebrew/lib/libabsl_synchronization.2308.0.0.dylib /opt/homebrew/lib/libgpr.dylib /opt/homebrew/lib/libgrpc++.dylib /opt/homebrew/lib/libgrpc.dylib libfastnetmon_grpc_pb_cc.a libfastnetmon_pb_cc.a /opt/homebrew/lib/libprotobuf.dylib /opt/homebrew/lib/libabsl_graphcycles_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_kernel_timeout_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_stacktrace.2308.0.0.dylib /opt/homebrew/lib/libabsl_symbolize.2308.0.0.dylib /opt/homebrew/lib/libabsl_malloc_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_debugging_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_demangle_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_time.2308.0.0.dylib /opt/homebrew/lib/libabsl_strings.2308.0.0.dylib /opt/homebrew/lib/libabsl_string_view.2308.0.0.dylib /opt/homebrew/lib/libabsl_strings_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_base.2308.0.0.dylib /opt/homebrew/lib/libabsl_spinlock_wait.2308.0.0.dylib /opt/homebrew/lib/libabsl_throw_delegate.2308.0.0.dylib /opt/homebrew/lib/libabsl_raw_logging_internal.2308.0.0.dylib /opt/homebrew/lib/libabsl_log_severity.2308.0.0.dylib /opt/homebrew/lib/libabsl_civil_time.2308.0.0.dylib /opt/homebrew/lib/libabsl_int128.2308.0.0.dylib /opt/homebrew/lib/libabsl_time_zone.2308.0.0.dylib -Wl,-framework,CoreFoundation
ld: Undefined symbols:
  absl::lts_20230802::cord_internal::InitializeCordRepExternal(std::__1::basic_string_view<char, std::__1::char_traits<char>>, absl::lts_20230802::cord_internal::CordRepExternal*), referenced from:
      absl::lts_20230802::Cord absl::lts_20230802::MakeCordFromExternal<grpc::ProtoBufferReader::MakeCordFromSlice(grpc_slice)::'lambda'(std::__1::basic_string_view<char, std::__1::char_traits<char>>)>(std::__1::basic_string_view<char, std::__1::char_traits<char>>, grpc::ProtoBufferReader::MakeCordFromSlice(grpc_slice)::'lambda'(std::__1::basic_string_view<char, std::__1::char_traits<char>>)&&) in fastnetmon_api_client.cpp.o
  absl::lts_20230802::Cord::DestroyCordSlow(), referenced from:
      absl::lts_20230802::Cord::~Cord() in fastnetmon_api_client.cpp.o
  absl::lts_20230802::Cord::Append(absl::lts_20230802::Cord&&), referenced from:
      grpc::ProtoBufferReader::ReadCord(absl::lts_20230802::Cord*, int) in fastnetmon_api_client.cpp.o
      grpc::ProtoBufferReader::ReadCord(absl::lts_20230802::Cord*, int) in fastnetmon_api_client.cpp.o
      grpc::ProtoBufferReader::ReadCord(absl::lts_20230802::Cord*, int) in fastnetmon_api_client.cpp.o
      grpc::ProtoBufferReader::ReadCord(absl::lts_20230802::Cord*, int) in fastnetmon_api_client.cpp.o
  absl::lts_20230802::Cord::Subcord(unsigned long, unsigned long) const, referenced from:
      grpc::ProtoBufferWriter::WriteCord(absl::lts_20230802::Cord const&) in libfastnetmon_grpc_pb_cc.a[2](fastnetmon.grpc.pb.cc.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [fastnetmon_api_client] Error 1
make[1]: *** [CMakeFiles/fastnetmon_api_client.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
pavel-odintsov commented 10 months ago

Thank you for working on it! Sorry about delate with review.

pavel-odintsov commented 9 months ago

Thank you very much for doing this change. I believe it's very reasonable approach to use cmake file supplied by Protobuf itself and use cmake one (which is on risk to be outdated) as second attempt.

pavel-odintsov commented 9 months ago

Awesome, built successfully: https://app.circleci.com/pipelines/github/pavel-odintsov/fastnetmon/1455/workflows/a634639e-294e-4c33-b909-dd7b8e732f9a