tkn-tub / ns3-gym

ns3-gym - The Playground for Reinforcement Learning in Networking Research
GNU General Public License v2.0
524 stars 198 forks source link

Fix generation of protobuf files #74

Closed a-andre closed 1 year ago

a-andre commented 1 year ago

The files are now generated during build.

Note: find_package now uses the cmake files provided by the Protobuf project and not the files from the CMake project, as the later cannot handle relative IMPORT_DIRS paths.

rukyr97 commented 1 year ago

After applying your patch, I am still getting: -- Could NOT find Protobuf (missing: Protobuf_DIR) during ns3 build, which results in ns3-gym module not being properly built ... but maybe this issue is not related to the patch.

a-andre commented 1 year ago

find_package() now requires the CMake files provided by protobuf, but Ubuntu and Debian don't ship these files yet. That's why you could not find protobuf. As a workaround you could build protobuf yourself (using CMake or Bazel).

rukyr97 commented 1 year ago

@a-andre, thank you for your quick answer. I have just built protobuf myself using CMake and the process was very straightforward. Now, the modules configured to be built are properly showing opengym. However, there are many new errors showing up during the ns-3 build process. I'm listing just the first three, as I believe they are somehow related to a mismatch of protobuf supported versions. What is the branch/tag of protobuf you have built?

Modules configured to be built: antenna applications bridge core flow-monitor internet internet-apps mobility network opengym propagation stats traffic-control ts

Modules that cannot be built: test

-- Configuring done -- Generating done -- Build files have been written to: /home/rukyr/workspace/ns-3-dev/cmake-cache Finished executing the following commands: mkdir cmake-cache cd cmake-cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=default -DNS3_ASSERT=ON -DNS3_LOG=ON -DNS3_WARNINGS_AS_ERRORS=OFF -DNS3_NATIVE_OPTIMIZATIONS=OFF -G Unix Makefiles .. ; cd .. [ 0%] Building CXX object CMakeFiles/stdlib_pch_exec.dir/cmake_pch.hxx.gch [ 1%] Building CXX object CMakeFiles/stdlib_pch.dir/cmake_pch.hxx.gch [ 1%] Building CXX object src/test/CMakeFiles/libtest.dir///build-support/empty.cc.o [ 1%] Building CXX object src/test/CMakeFiles/libtest.dir/ns3tcp/ns3tcp-socket-writer.cc.o [ 1%] Building CXX object CMakeFiles/stdlib_pch.dir/build-support/empty.cc.o [ 1%] Building CXX object CMakeFiles/stdlib_pch_exec.dir/build-support/empty-main.cc.o [ 1%] Building CXX object src/test/CMakeFiles/libtest.dir/traced/traced-value-callback-typedef-test-suite.cc.o [ 1%] Building CXX object src/test/CMakeFiles/libtest.dir/ns3tc/fq-cobalt-queue-disc-test-suite.cc.o [ 2%] Linking CXX executable ns3-dev-stdlib_pch_exec-default [ 3%] Building CXX object src/test/CMakeFiles/libtest.dir/ns3tc/fq-codel-queue-disc-test-suite.cc.o [ 3%] Building CXX object src/test/CMakeFiles/libtest.dir/ns3tc/fq-pie-queue-disc-test-suite.cc.o [ 3%] Building CXX object src/test/CMakeFiles/libtest.dir/ns3tc/pfifo-fast-queue-disc-test-suite.cc.o [ 4%] Running cpp protocol buffer compiler on model/messages.proto [ 4%] Building CXX object contrib/opengym/CMakeFiles/libopengym-obj.dir/helper/opengym-helper.cc.o [ 4%] Building CXX object contrib/opengym/CMakeFiles/libopengym-obj.dir/model/container.cc.o In file included from /home/rukyr/workspace/ns-3-dev/contrib/opengym/model/container.h:27, from /home/rukyr/workspace/ns-3-dev/contrib/opengym/model/container.cc:23: /home/rukyr/workspace/ns-3-dev/contrib/opengym/model/messages.pb.h:17:2: error: #error This file was generated by an older version of protoc which is 17 | #error This file was generated by an older version of protoc which is | ^~~~~ /home/rukyr/workspace/ns-3-dev/contrib/opengym/model/messages.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please 18 | #error incompatible with your Protocol Buffer headers. Please | ^~~~~ /home/rukyr/workspace/ns-3-dev/contrib/opengym/model/messages.pb.h:19:2: error: #error regenerate this file with a newer version of protoc. 19 | #error regenerate this file with a newer version of protoc. | ^~~~~

a-andre commented 1 year ago

You have to point Protobuf_PROTOC_EXECUTABLE (or similar) to the protoc you built manually, to fix the version mismatch.

My distribution provides Protobuf's CMake files, so I don't have to build it myself. Currently using Protobuf 21.12.

rukyr97 commented 1 year ago

Thank you for the quick reply @a-andre . I'm not sure where to look for in order to achieve that. Google did not help :( Could you please provide me additional information? Thank you in advance!

I removed from my system the previously installed packages libprotobuf-dev and protobuf-compiler (with apt) and built the main branch of protobuf. protoc --version outputs libprotoc 21.12

a-andre commented 1 year ago

It seems Protobuf_PROTOC_EXECUTABLE is no longer used.

Can you remove the generated messages.pb.h and messages.pb.cc, so that they are generated again.

If it still doesn't work, you can check if the correct protoc is used with adding the following after find_package(Protobuf CONFIG 3.0.0):

get_target_property(PROTOC_LOCATION protobuf::protoc LOCATION)
message("protoc location: ${PROTOC_LOCATION}")
rukyr97 commented 1 year ago

Thank you once again. Removing the generated protobuf messages fixed the building problems. I'm currently building ns-3 now to check if the patch fixes the problem and I can resume using ns3-gym with the recent ns-3 versions. I'll update you afterwards.

After adding the message to the CMakeLists.txt file, the output was /usr/local/bin/protoc-3.21.4.0 so I guess everything is fine now. Still I am confused with the versioning, since i was expecting the binary name to have same version of protoc --version output, which was 21.12

0 lrwxrwxrwx 1 root root 15 Jan 5 10:09 /usr/local/bin/protoc -> protoc-3.21.4.0 13208 -rwxr-xr-x 1 root root 13523864 Jan 4 16:24 /usr/local/bin/protoc-3.19.5.0 13204 -rwxr-xr-x 1 root root 13520216 Jan 4 15:55 /usr/local/bin/protoc-3.19.6.0 19944 -rwxr-xr-x 1 root root 20419912 Jan 5 09:50 /usr/local/bin/protoc-3.21.4.0

a-andre commented 1 year ago

See https://developers.google.com/protocol-buffers/docs/news/2022-05-06 for information about the versioning.

rukyr97 commented 1 year ago

A completely different error has now shown up during the build process. Below is a snippet of the error stack. Do you have any clue on what may be the issue now?

[ 77%] Building CXX object src/propagation/CMakeFiles/libpropagation-obj.dir/model/okumura-hata-propagation-loss-model.cc.o [ 77%] Linking CXX shared library ../../../build/lib/libns3-dev-opengym-default.so [ 77%] Building CXX object src/internet/CMakeFiles/libinternet-obj.dir/model/ipv6-header.cc.o /usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.cc.o): relocation R_X86_64_TPOFF32 against hidden symbol `_ZN6google8protobuf8internal15ThreadSafeArena13thread_cache_E' can not be used when making a shared object /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status gmake[2]: [contrib/opengym/CMakeFiles/libopengym.dir/build.make:141: ../build/lib/libns3-dev-opengym-default.so] Error 1 gmake[1]: [CMakeFiles/Makefile2:1278: contrib/opengym/CMakeFiles/libopengym.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs.... [ 77%] Building CXX object src/internet/CMakeFiles/libinternet-obj.dir/model/ipv6-interface-address.cc.o

a-andre commented 1 year ago

I haven't seen that issue before, maybe because I'm using the shared version (.so) of the protobuf library; the static version (.a) is not available on my system.

rukyr97 commented 1 year ago

Is there any way to build the source code of the protobuf library specifying the shared version of the library? Is this something I need to change in the CMakeLists.txt of ns3-gym? Not sure how to configure my system the same way as yours.

Sorry for these dumb questions. It is the first time I am dealing with protobuf, and CMake troubleshooting, and the learning curve is a bit stiff!

a-andre commented 1 year ago

You can build protobuf with -Dprotobuf_BUILD_SHARED_LIBS=ON to get the shared libs.

rukyr97 commented 1 year ago

Unfortunately, when building with the flag you mentioned, I'm now getting the errors below.

I noticed there are some related issues in the protobuf repo. I'll have a look into this in the upcoming days and try to get back if got any news.

[ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_import_lite.pb.cc.o [ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_import_public_lite.pb.cc.o [ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_lite.pb.cc.o [ 89%] Linking CXX executable tests /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/testing/googletest.cc.o: in function google::protobuf::(anonymous namespace)::GetTemporaryDirectoryName()': googletest.cc:(.text+0x2ee): warning: the use oftmpnam' is dangerous, better use mkstemp' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in functiongoogle::protobuf::(anonymous namespace)::RepeatedField_Cords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x10af4): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10b40): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10b8c): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10bd8): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10c24): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10c41): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10d1d): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e3e): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e5d): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Swap(google::protobuf::RepeatedField<absl::lts_20220623::Cord>*)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e69): undefined reference togoogle::protobuf::RepeatedField::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10f2e): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11005): undefined reference togoogle::protobuf::RepeatedField::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x110ca): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x111a6): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11298): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11374): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11457): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11540): undefined reference togoogle::protobuf::RepeatedField::Clear()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1154c): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11635): undefined reference togoogle::protobuf::RepeatedField::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11641): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11a9e): undefined reference togoogle::protobuf::RepeatedField::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11ab3): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in functiongoogle::protobuf::(anonymous namespace)::RepeatedField_TruncateCords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x11b6a): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11bb6): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c02): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c4e): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c66): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11d2b): undefined reference togoogle::protobuf::RepeatedField::Truncate(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11d37): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11e2b): undefined reference togoogle::protobuf::RepeatedField::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11e43): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11f08): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11fdf): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11fef): undefined reference togoogle::protobuf::RepeatedField::Truncate(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11ffb): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x121b5): undefined reference togoogle::protobuf::RepeatedField::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::(anonymous namespace)::RepeatedField_ResizeCords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x1226e): undefined reference togoogle::protobuf::RepeatedField::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12286): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1237c): undefined reference togoogle::protobuf::RepeatedField::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12394): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1248a): undefined reference togoogle::protobuf::RepeatedField::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x124a2): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12579): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12661): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1273d): undefined reference togoogle::protobuf::RepeatedField::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12819): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12926): undefined reference togoogle::protobuf::RepeatedField::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1293e): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::empty() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12a24): undefined reference togoogle::protobuf::RepeatedField::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12d2e): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in functiongoogle::protobuf::RepeatedField::RemoveLast()': repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0x93): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0xa4): undefined reference togoogle::protobuf::RepeatedField::Mutable(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0xc3): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::ExchangeCurrentSize(int)' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in functiongoogle::protobuf::RepeatedField::SwapElements(int, int)': repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii]+0x24): undefined reference to google::protobuf::RepeatedField<absl::lts_20220623::Cord>::Mutable(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii]+0x38): undefined reference togoogle::protobuf::RepeatedField::Mutable(int)' collect2: error: ld returned 1 exit status gmake[2]: [CMakeFiles/tests.dir/build.make:2162: tests] Error 1 gmake[1]: [CMakeFiles/Makefile2:1012: CMakeFiles/tests.dir/all] Error 2 gmake: *** [Makefile:146: all] Error 2

rukyr97 commented 1 year ago

I managed to build, ctest and install protobuf successfully now, however I am still not sucessfull with building ns3-gym. I'm not sure if the problem I am facing at the moment is still related to protobuf or if you came across this when building it yourself too.

Consolidate compiler generated dependencies of target stdlib_pch Consolidate compiler generated dependencies of target stdlib_pch_exec [ 0%] Running python protocol buffer compiler on model/messages.proto /usr/local/bin/protoc-3.21.4.0: error while loading shared libraries: libabsl_city.so.2206.0.0: cannot open shared object file: No such file or directory gmake[2]: [contrib/opengym/CMakeFiles/libopengym-obj.dir/build.make:83: ../contrib/opengym/model/ns3gym/ns3gym/messages_pb2.py] Error 127 gmake[1]: [CMakeFiles/Makefile2:1251: contrib/opengym/CMakeFiles/libopengym-obj.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs....

a-andre commented 1 year ago

Try this:

git clone --recurse-submodules --branch v21.12 https://github.com/protocolbuffers/protobuf.git
cd protobuf
mkdir build
cd build
cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF ..
make
make install  # might need root rights
rukyr97 commented 1 year ago

Sorry for the delay... I finally got ns3-gym working again. Thank you for the pull request, and for the patience to guide me through the issues I had.

On top of your comment, i also had to do this here because of a missing file.

I think this protobuf dependency install process should be properly documented for future users

pgawlowicz commented 1 year ago

Hi, thanks for this patch!

pgawlowicz commented 1 year ago

Hi guys, could I ask you to test a fresh installation of the app-ns-3.36+?? Thank you!

rukyr97 commented 1 year ago

It works for me!