经过大约一天的故障排除后,我确定了一个解决方案。尽管可以自己调用 tao_idl 和 opendds_idl,但您基本上不应该这样做。需要大量命令行参数才能使两者都工作,如果它们不存在,每个 exe 都会在没有正确推理的情况下崩溃。
我将在下面添加我的步骤以使用 OpenDDS 创建一个新的基本的两个 exe 发布/订阅项目:
- 创建您自己的 IDL 文件。
- 从 DCPS Messenger 示例开始,修改 .mpc 文件,替换
Messenger.idl
为您的 IDL 文件名。
创建一个名为 的新文件<your project>.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
}
打开一个新的 VS 命令行终端并运行$DDS_ROOT/setenv.cmd
,或者如果您通过 Windows 设置设置了这些环境变量,则打开一个常规终端。
导航到您的项目目录并调用:mwc.pl -type vs2017
,根据构建工具/IDE 的需要替换“vs2017”。
打开生成的解决方案,并根据您的 Windows SDK 版本重新定位它。
首先构建<your project>_IDL
项目。如果您在输出窗口中注意到,它会自动调用tao_idl
andopendds_idl
命令。您可以查看.vcxproj
文件以查看原始问题的完整命令行参数。
修改publisher.cpp
、subscriber.cpp
和DataReaderListenerImpl.cpp
文件以匹配您的新 IDL。像往常一样运行示例,然后 ta-da!
为了完整起见,两者的完整命令tao_idl
和opendds_idl
如下:
> opendds_idl -Sa -St "<your file>.idl"
> tao_idl -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -Sa -St -I$(DDS_ROOT) "<your file>.idl"
> tao_idl -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -Sa -St -I$(DDS_ROOT) "<your file>TypeSupport.idl"