hust-diangroup / ns3-ai

Enable the interaction between ns-3 and popular frameworks using Python, which mean you can train and test your AI algorithms in ns-3 without changing any frameworks you are using now!
GNU General Public License v2.0
232 stars 83 forks source link

undefined reference to "shm_xxx" #111

Open mkris0714 opened 7 months ago

mkris0714 commented 7 months ago

In the ns3-ai build processing, the below undefined error occurred.

It's the problem that cmake should be performed including the option "-lrt".

I tried to address the problem using in "set(CXXFLAGS="-lrt") command" or ns3 configure CXXFLAGS, but I failed.

How can I fix it ?

[100%] Linking CXX shared library /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/lib/libns3.38-core-default.so [100%] Linking CXX shared library /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/lib/libns3.38-ai-default.so [100%] Building CXX object contrib/ai/examples/a-plus-b/CMakeFiles/ns3ai_apb_gym.dir/use-gym/apb.cc.o [100%] Linking CXX executable /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/contrib/ai/examples/a-plus-b/ns3.38-ns3ai_apb_gym-default /usr/bin/ld: /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/lib/libns3.38-ai-default.so: undefined reference to shm_open' /usr/bin/ld: /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/lib/libns3.38-ai-default.so: undefined reference toshm_unlink' collect2: error: ld returned 1 exit status make[3]: [contrib/ai/examples/a-plus-b/CMakeFiles/ns3ai_apb_gym.dir/build.make:101: /root/impl_source/netai_impl/learning/environments/ns-allinone-3.38/ns-3.38/build/contrib/ai/examples/a-plus-b/ns3.38-ns3ai_apb_gym-default] Error 1 make[2]: [CMakeFiles/Makefile2:4673: contrib/ai/examples/a-plus-b/CMakeFiles/ns3ai_apb_gym.dir/all] Error 2 make[1]: [CMakeFiles/Makefile2:4679: contrib/ai/examples/a-plus-b/CMakeFiles/ns3ai_apb_gym.dir/rule] Error 2 make: [Makefile:1038: ns3ai_apb_gym] Error 2 Finished executing the following commands: cd cmake-cache; /usr/local/bin/cmake --build . -j 7 --target ns3ai_apb_gym ; cd ..

mkris0714 commented 7 months ago

I temporarily fixed the linking error by modifying the build file, build-support/macros-and-definitions.cmake.

However, new command lines will be needed for building dependency to ns3-ai modules.

if(${NS3_STATIC} AND (NOT BEXEC_STANDALONE)) target_link_libraries( ┆ ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE_STATIC} ┆ ${lib-ns3-static} ) elseif(${NS3_MONOLIB} AND (NOT BEXEC_STANDALONE)) target_link_libraries( ┆ ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE} ┆ ${lib-ns3-monolib} ${LIB_AS_NEEDED_POST} ) else() target_link_libraries( ┆ ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE} ┆ "${BEXEC_LIBRARIES_TO_LINK}" ${LIB_AS_NEEDED_POST} "-lrt" ) endif()

ShenMuyuan commented 7 months ago

Hi, @mkris0714. Could you provide your OS version and the command you are running, to reproduce the error?

mkris0714 commented 7 months ago

Hi, @ShenMuyuan.

In addition, "ns3-ai v1.2.0" is compatible with ns3 version 3.37, not with version 3.38 (based on "rl-tcp example" execution).

please check, ns3-ai v1.2.0 with ns3 3.38

Thank you !

ShenMuyuan commented 7 months ago

OS version : Linux 20.04 on docker (no conda) All required libraries are installed

In development of the main branch, we used a mix of Ubuntu 22.04 virtual machine and WSL, rather than Ubuntu 20.04 in docker. Your issue may be the difference of system libraries, as in our Ubuntu 22.04 the ns3ai_apb_gym can run without librt linking explicitly.

So, 1) If you keep using your platform, you can try to add rt in ns3-ai's LIBRARIES_TO_LINK, like:

build_lib(
        LIBNAME ai
        SOURCE_FILES ${msg_interface_srcs} ${gym_interface_srcs}
        HEADER_FILES ${msg_interface_hdrs} ${gym_interface_hdrs}
        LIBRARIES_TO_LINK ${libcore} Boost::program_options protobuf::libprotobuf rt
)

This method avoids changing the global build process of ns-3.

2) Alternatively, you could switch to Ubuntu 22.04, in virtual machine or WSL.

"ns3-ai v1.2.0" is compatible with ns3 version 3.37, not with version 3.38

The v1.2.0 is outdated (with the old API) and we have no plan to update its compatibility. We will release a new version soon (with the new API), based on current main branch.

mkris0714 commented 7 months ago

Thank you for your kind solution !

I support the ns3-ai module. That module is very convenient for running rl on ns3.

Have a nice day