build Hello world with cmake

3 posts / 0 new
Last post
gabim's picture
Offline
Last seen: 3 years 2 months ago
Joined: 07/17/2020
Posts: 7
build Hello world with cmake

Hi,

i need to run Helloworld with cmake so i made a CMakeLists.txt file and it run without problems .

this is the content of CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)

project(HelloWorldCmake VERSION 1.0.0)

message(STATUS "print NDDSHOME:" $ENV{NDDSHOME})

#target_compile_definitions(src -DRTI_UNIX -DRTI_LINUX -DRTI_64BIT)
include_directories($ENV{NDDSHOME}/include $ENV{NDDSHOME}/include/ndds)
#include_directories($ENV{NDDSHOME}/include/ndds)

 

add_executable(HelloWorldWithCmake
src/HelloWorldSupport.cxx
src/HelloWorld_subscriber.cxx
src/HelloWorld_publisher.cxx
src/HelloWorldPlugin.cxx
src/HelloWorld.cxx)

target_link_libraries(HelloWorldWithCmake
PUBLIC ${CONNEXTDDS_CPP2_API_LIBRARIES_RELEASE_SHARED}
)

target_include_directories(HelloWorldWithCmake
PUBLIC ${PROJECT_BINARY_DIR}
PUBLIC ${PROJECT_SOURCE_DIR}
PUBLIC ${CONNEXTDDS_INCLUDE_DIRS}
)

target_compile_definitions(HelloWorldWithCmake
PUBLIC RTI_UNIX
PUBLIC RTI_LINUX
PUBLIC RTI_64BIT
)

but when i rum make  (or cmake --build .)

i got the following errors:

usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o: in function `HelloWorldDataWriter::delete_data(HelloWorld*, DDS_TypeDeallocationParams_t const&)':
HelloWorldSupport.cxx:(.text+0xba): undefined reference to `DDSLog_g_instrumentationMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0xc7): undefined reference to `DDSLog_g_submoduleMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0xe1): undefined reference to `DDS_LOG_BAD_PARAMETER_s'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x109): undefined reference to `RTILog_printLocationContextAndMsg'
/usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o: in function `HelloWorldDataWriter::get_loan(HelloWorld*&)':

i add also run:

make VERBOSE=1

and those the results:

/usr/local/bin/cmake -S/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake -B/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build/CMakeFiles /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build'
make -f CMakeFiles/HelloWorldWithCmake.dir/build.make CMakeFiles/HelloWorldWithCmake.dir/depend
make[2]: Entering directory '/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build'
cd /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build /home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build/CMakeFiles/HelloWorldWithCmake.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build'
make -f CMakeFiles/HelloWorldWithCmake.dir/build.make CMakeFiles/HelloWorldWithCmake.dir/build
make[2]: Entering directory '/home/gabi/rti_workspace/6.0.1/examples/connext_dds/c++/hello_world_cmake/build'
[ 16%] Linking CXX executable HelloWorldWithCmake
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/HelloWorldWithCmake.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorld_subscriber.cxx.o CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorld_publisher.cxx.o CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldPlugin.cxx.o CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorld.cxx.o -o HelloWorldWithCmake
/usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorld_publisher.cxx.o: in function `main':
HelloWorld_publisher.cxx:(.text+0x47a): multiple definition of `main'; CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorld_subscriber.cxx.o:HelloWorld_subscriber.cxx:(.text+0x6e5): first defined here
/usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o: in function `HelloWorldDataWriter::delete_data(HelloWorld*, DDS_TypeDeallocationParams_t const&)':
HelloWorldSupport.cxx:(.text+0xba): undefined reference to `DDSLog_g_instrumentationMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0xc7): undefined reference to `DDSLog_g_submoduleMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0xe1): undefined reference to `DDS_LOG_BAD_PARAMETER_s'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x109): undefined reference to `RTILog_printLocationContextAndMsg'
/usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o: in function `HelloWorldDataWriter::get_loan(HelloWorld*&)':
HelloWorldSupport.cxx:(.text+0x153): undefined reference to `DDSLog_g_instrumentationMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x160): undefined reference to `DDSLog_g_submoduleMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x17a): undefined reference to `RTI_LOG_ANY_s'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x1a2): undefined reference to `RTILog_printLocationContextAndMsg'
/usr/bin/ld: CMakeFiles/HelloWorldWithCmake.dir/src/HelloWorldSupport.cxx.o: in function `HelloWorldDataWriter::discard_loan(HelloWorld&)':
HelloWorldSupport.cxx:(.text+0x1d3): undefined reference to `DDSLog_g_instrumentationMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x1e0): undefined reference to `DDSLog_g_submoduleMask'
/usr/bin/ld: HelloWorldSupport.cxx:(.text+0x1fa): undefined reference to `RTI_LOG_ANY_s'

Thanks

Keywords:
Offline
Last seen: 1 month 1 week ago
Joined: 09/23/2018
Posts: 62

Most of the examples in the following github repo are Cmake based .. you might find them helpful.

 

https://github.com/rticommunity/rticonnextdds-examples

 

gabim's picture
Offline
Last seen: 3 years 2 months ago
Joined: 07/17/2020
Posts: 7

Thanks for this information.

 i will explore it