First Application
This guide shows the quickest path to your first AstuteDDS publisher and subscriber using the installed developer package and IDL compiler.
Pre-Install Prerequisites
Ensure your build toolchain is available:
cmake --version
Compiler check examples:
# Linux / macOS
c++ --version
# Windows (Developer Command Prompt)
cl
1. Install the Developer Package
Install the package for your platform:
- Windows:
astutedds-dev-*-windows-x64.msi - Debian/Ubuntu:
astutedds-dev_*_amd64.deb - RHEL/Rocky/AlmaLinux:
astutedds-dev-*-x86_64.rpm
For exact install commands and package verification, see Developer Packages.
2. Verify Installed Tooling
Confirm the IDL compiler is available after package installation:
astutedds-idl --help
3. Create Project Layout
mkdir -p hello-astutedds/src
cd hello-astutedds
4. Create a Minimal IDL Type
Create HelloWorld.idl:
module Demo {
@final
struct HelloWorld {
@key unsigned long id;
string<128> message;
};
};
5. Generate C++ Code from IDL
mkdir -p generated
astutedds-idl -o generated HelloWorld.idl
Generated files:
generated/HelloWorld.hppgenerated/HelloWorld.cpp
6. Add Publisher and Subscriber Sources
Create src/hello_publisher.cpp:
#include "HelloWorld.hpp"
#include <astutedds/dcps/CorePolicy.hpp>
#include <astutedds/dcps/dcps.hpp>
#include <astutedds/dcps/qos.hpp>
#include <chrono>
#include <iostream>
#include <thread>
int main()
{
dds::domain::DomainParticipant participant(0, 0);
dds::topic::Topic<Demo::HelloWorld> topic(participant, "HelloWorldTopic");
dds::pub::Publisher publisher(participant);
astutedds::dcps::DataWriterQos wqos{};
wqos.reliability.kind = astutedds::dcps::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
dds::pub::DataWriter<Demo::HelloWorld> writer(publisher, topic, wqos);
Demo::HelloWorld sample;
sample.id(1);
sample.message("Hello from AstuteDDS");
if (writer.write(sample))
{
std::cout << "Published HelloWorld sample" << std::endl;
}
// Give discovery and transport a brief window before process exit.
std::this_thread::sleep_for(std::chrono::seconds(1));
return 0;
}
Create src/hello_subscriber.cpp:
#include "HelloWorld.hpp"
#include <astutedds/dcps/CorePolicy.hpp>
#include <astutedds/dcps/dcps.hpp>
#include <astutedds/dcps/qos.hpp>
#include <chrono>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
int main()
{
dds::domain::DomainParticipant participant(0, 0);
dds::topic::Topic<Demo::HelloWorld> topic(participant, "HelloWorldTopic");
dds::sub::Subscriber subscriber(participant);
astutedds::dcps::DataReaderQos rqos{};
rqos.reliability.kind = astutedds::dcps::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
dds::sub::DataReader<Demo::HelloWorld> reader(subscriber, topic, rqos);
std::cout << "Waiting for HelloWorld samples..." << std::endl;
while (true)
{
Demo::HelloWorld sample{};
astutedds::dcps::SampleInfo info{};
while (reader.take_next(sample, info) == astutedds::dcps::ReturnCode_t::RETCODE_OK)
{
if (info.valid_data)
{
std::cout << "Received id=" << sample.id()
<< " message=\"" << sample.message() << "\"" << std::endl;
}
}
std::this_thread::sleep_for(100ms);
}
return 0;
}
7. Create CMake Build
Create CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(HelloAstuteDDS LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(AstuteDDS REQUIRED)
find_package(Threads REQUIRED)
add_executable(hello_publisher
src/hello_publisher.cpp
generated/HelloWorld.cpp
)
add_executable(hello_subscriber
src/hello_subscriber.cpp
generated/HelloWorld.cpp
)
target_include_directories(hello_publisher PRIVATE generated)
target_include_directories(hello_subscriber PRIVATE generated)
target_link_libraries(hello_publisher PRIVATE
AstuteDDS::astutedds
Threads::Threads
)
target_link_libraries(hello_subscriber PRIVATE
AstuteDDS::astutedds
Threads::Threads
)
8. Build and Run
Build both executables:
cmake -S . -B build
cmake --build build -j
If CMake cannot find AstuteDDS, set the install prefix explicitly:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/opt/astutedds
Typical installation prefix examples:
- Windows:
-DCMAKE_PREFIX_PATH="C:/Program Files/AstuteDDS" - Debian/Ubuntu:
-DCMAKE_PREFIX_PATH=/opt/astutedds - RHEL/Rocky/AlmaLinux:
-DCMAKE_PREFIX_PATH=/opt/astutedds
Run subscriber in terminal 1:
./build/hello_subscriber
Run publisher in terminal 2:
./build/hello_publisher
Expected output from publisher:
Published HelloWorld sample
Expected output from subscriber:
Received id=1 message="Hello from AstuteDDS"
Stop both applications with Ctrl+C when finished.
Troubleshooting Discovery
If publisher/subscriber do not match:
- Confirm both use the same domain ID.
- Validate local discovery and endpoint visibility in
astutedds-inspect. - For explicit peers or interface pinning, configure discovery using JSON Discovery Config.
Next Step
Continue with QoS Introduction to learn how reliability, durability, history, and deadlines change runtime behavior.