GRC C++ Generation: Difference between revisions
(Created page with "Note: This page is a work in progress. Starting from GNU Radio 3.8, GRC allows you to generate C++ code (not just Python) from your flowgraph. This feature was a SOCIS (ESA Summer of Code in Space) project in 2017. The C++ generation mode is significantly less stable and feature-rich than the default Python mode, since Python is a far more flexible language (and since GRC was created to generate Python code). About 50% of the in-tree blocks support C++ generation. The C...") |
No edit summary |
||
Line 9: | Line 9: | ||
* CMakeLists.txt | * CMakeLists.txt | ||
All of these files are generated from templates, and changes in your flowgraph will be reflected in them. Additionally, GRC creates a build directory which you can call cmake and make from. Pressing the execute button in GRC will generate, compile and run your flowgraph. | All of these files are generated from templates, and changes in your flowgraph will be reflected in them. Additionally, GRC creates a build directory which you can call cmake and make from. Pressing the execute button in GRC will generate, compile and run your flowgraph. However, it is often convenient to compile and run your flowgraph in a separate terminal. | ||
= Adding C++ Templates to a Block = | == Adding C++ Templates to a Block == | ||
This guide builds on the [https://wiki.gnuradio.org/index.php?title=Creating_c%2B%2B_OOT_with_gr-modtool C++ OOT guide]. The steps listed here will fall between [https://wiki.gnuradio.org/index.php?title=Creating_c%2B%2B_OOT_with_gr-modtool#Modifying_the_YAML_.yml_File Modifying the YAML file] and [https://wiki.gnuradio.org/index.php?title=Creating_c%2B%2B_OOT_with_gr-modtool#Compiling_and_Installing_the_Block Compiling_and_Installing_the_Block]. | |||
In order to enable C++ generation for our multDivSelect block, we need to add some additional lines to the YAML file (comments have been removed for brevity): | |||
== | <syntaxhighlight lang="yaml" line="line" highlight="4, 10-14"> | ||
id: customModule_multDivSelect | |||
label: multDivSelect | |||
category: '[customModule]' | |||
flags: [cpp] | |||
templates: | |||
imports: from gnuradio import customModule | |||
make: customModule.multDivSelect(${selector}) | |||
== Runtime Issues == | cpp_templates: | ||
includes: ['#include <gnuradio/customModule/multDivSelect.h>'] | |||
declarations: 'customModule::multDivSelect::sptr ${id};' | |||
link: ['gnuradio-customModule'] | |||
make: 'this->${id} = customModule::multDivSelect::make(${selector});' | |||
parameters: | |||
- id: selector | |||
label: Selector, Multiply (true) or Divide (false) | |||
dtype: bool | |||
default: true | |||
inputs: | |||
- label: in0 | |||
domain: stream | |||
dtype: complex | |||
- label: in1 | |||
domain: stream | |||
dtype: complex | |||
outputs: | |||
- label: out0 | |||
domain: stream | |||
dtype: complex | |||
file_format: 1</syntaxhighlight> | |||
== Troubleshooting == | |||
=== Generation Issues === | |||
=== Compilation Issues === | |||
=== Runtime Issues === |
Revision as of 08:33, 14 August 2022
Note: This page is a work in progress.
Starting from GNU Radio 3.8, GRC allows you to generate C++ code (not just Python) from your flowgraph. This feature was a SOCIS (ESA Summer of Code in Space) project in 2017. The C++ generation mode is significantly less stable and feature-rich than the default Python mode, since Python is a far more flexible language (and since GRC was created to generate Python code). About 50% of the in-tree blocks support C++ generation. The C++ generation templates have to be written on a per-block basis, which is a considerable amount of work. This also means that it is a considerable amount of work to keep the C++ templates updated, which is why some blocks' templates may be outdated and produce errors. The good news is that these errors often have trivial fixes.
GRC generates C++ code by creating a new directory with three files:
- top_block.cpp
- top_block.hpp
- CMakeLists.txt
All of these files are generated from templates, and changes in your flowgraph will be reflected in them. Additionally, GRC creates a build directory which you can call cmake and make from. Pressing the execute button in GRC will generate, compile and run your flowgraph. However, it is often convenient to compile and run your flowgraph in a separate terminal.
Adding C++ Templates to a Block
This guide builds on the C++ OOT guide. The steps listed here will fall between Modifying the YAML file and Compiling_and_Installing_the_Block.
In order to enable C++ generation for our multDivSelect block, we need to add some additional lines to the YAML file (comments have been removed for brevity):
id: customModule_multDivSelect
label: multDivSelect
category: '[customModule]'
flags: [cpp]
templates:
imports: from gnuradio import customModule
make: customModule.multDivSelect(${selector})
cpp_templates:
includes: ['#include <gnuradio/customModule/multDivSelect.h>']
declarations: 'customModule::multDivSelect::sptr ${id};'
link: ['gnuradio-customModule']
make: 'this->${id} = customModule::multDivSelect::make(${selector});'
parameters:
- id: selector
label: Selector, Multiply (true) or Divide (false)
dtype: bool
default: true
inputs:
- label: in0
domain: stream
dtype: complex
- label: in1
domain: stream
dtype: complex
outputs:
- label: out0
domain: stream
dtype: complex
file_format: 1