【原创】OpenDDS笔记(三) Linux环境下的开发实例

       之前有写过一篇《OpenDDS笔记(一) Windows环境下的开发实例》,本篇以相同的IDL,h,Cpp,ini文件在Linux下进行实现。即Demo.idl,Publisher.cpp,Subscriber.cpp,DataReaderListener.h,DataReaderListener.cpp,config_Pub.ini,config_Sub.ini沿用《OpenDDS笔记(一) Windows环境下的开发实例》中的代码,需要的客官请移步:https://blog.csdn.net/jam12315/article/details/113388662

一、定义IDL文件

      将Demo.idl,Publisher.cpp,Subscriber.cpp,DataReaderListener.h,DataReaderListener.cpp,config_Pub.ini,config_Sub.ini拷贝到ubuntu文件夹下,本篇路径为:/home/jamie/DevOpenDDS/Demo

 

二、生成Export头文件

    cd到IDL文件所在目录下,通过以下命令自动生成xxxx_Export.h

perl $ACE_ROOT/bin/generate_export_file.pl DemoIDL > DemoIDL_Export.h

三、定义Demo.mwc、Demo.mpc

Demo.mwc定义如下:

workspace {
  // the -relative and -include cmdlines make it so this workspace
  // does not have to be in the $DDS_ROOT directory tree.

  // tell MPC to substitute our DDS_ROOT environment variables for relative paths
  cmdline += -relative DDS_ROOT=$DDS_ROOT

  // tell the projects where to find the DDS base projects (*.mpb)
  cmdline += -include $DDS_ROOT/MPC/config

}

这段代码直接复制过去就可以了,一般不用更改。

 

Demo.mpc定义如下:

       下面的代码包含3个工程。*.Idl,Publisher,Subscriber,代码看起来很唬人,不要怕,我们把主要的一说,其他都拷贝过去就行了,记得使用时删除//及后面的注释

project(*Idl) : dcps {                                                                                    //IDL工程
  sharedname     = DemoIdl                                                                        //库名称
  dynamicflags   = DEMOIDL_BUILD_DLL                                                 //宏定义前面几个字符与库名称保持一致,便于理解。
  libout         = .
  requires += tao_orbsvcs
  requires += no_opendds_safety_profile
  after    += Svc_Utils
  includes      += $(TAO_ROOT)/orbsvcs
  idlflags      += -I$(TAO_ROOT)/orbsvcs \
                   -Wb,export_macro=DemoIDL_Export \                                   //与第二步所述的头文件保持一致就可以了。
                   -Wb,export_include=DemoIDL_Export.h                                 //与第二步所述的头文件保持一致就可以了。
  dcps_ts_flags += -Wb,export_macro=DemoIDL_Export                          //与第二步所述的头文件保持一致就可以了。

  TypeSupport_Files {
    Demo.idl                                                                                                 //与第一步的IDL文件名保持一致
  }

  IDL_Files {
    Demo.idl                                                                                                //与第一步的IDL文件名保持一致
  }

  // We only want the generated files
  Header_Files {
  }

  // We only want the generated files
  Source_Files {
  }
}

project(Publisher) : dcpsexe, dcps_tcp, svc_utils {                                  //Publisher工程
  after    += *Idl                                                                                         //编译依赖于上述IDL工程
  exename   = Publisher                                                                           //生成的可执行程序的名称
  requires += tao_orbsvcs
  requires += no_opendds_safety_profile

  includes += $(TAO_ROOT)/orbsvcs
  libs     += DemoIdl                                                                                  //依赖库,为上面飙蓝的库名称

  IDL_Files {
  }

  TypeSupport_Files {
  }

  Header_Files {
  }

  Source_Files {
    Publisher.cpp                                                                                       //已经写好的Publisher.cpp文件
  }
}

project(Subscriber) : dcpsexe, dcps_tcp {                                               //Subscriber工程
  after    += *Idl                                                                                         //编译依赖于上述IDL工程
  exename   = Subscriber                                                                        //生成的可执行程序的名称
  requires += tao_orbsvcs
  requires += no_opendds_safety_profile

  includes += $(TAO_ROOT)/orbsvcs
  libs     += DemoIdl                                                                                 //依赖库,为上面飙蓝的库名称

  TypeSupport_Files {
  }

  IDL_Files {
  }

  Header_Files {
  }

  Source_Files {
    Subscriber.cpp                                                                                   //已经写好的Subscriber.cpp文件
    DataReaderListener.cpp                                                                    //已经写好的DataReaderListener.cpp文件
  }

}

四、生成代码

       1. cd到IDL目录下,执行$ACE_ROOT/bin/mwc.pl -type make产生Makefile

       
       2. 执行make产生libDemoIdl.so库,及可执行程序Publicsher,Subscriber

五、执行

    根据本人《OpenDDS笔记(一) Windows环境下的开发实例》中所述,配置文件已将发现方式设置为对等发现,因此不分先后得运行Publisher,Subscriber,就可以实现同样得功能。

 

  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jamie.T

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值