Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error when generating code/config for protoc generated C++ code #22

Open
eliott-arkeale opened this issue Oct 1, 2024 · 1 comment

Comments

@eliott-arkeale
Copy link

eliott-arkeale commented Oct 1, 2024

C++ code generated by protoc (protobuf compiler) can lead to parsing errors when generating C++ code or config with plcncli using one of the following commands:

plcncli generate code
plcncli generate config
plcncli generate all

Error looks like this:

exchange.pb.h(407,0): error CPP0005: A parsing exception was thrown.

parsing exception occured while parsing 'brace_group' expected '(skip([}]) + skip(multiline_ws*))' at line number 407, and character number 0

A fix has been documented on the PLCNext Community forum (here).
You have to move all your protoc generated C++ files from src to another directory. For example, rpc/. To include these files during compilation, you have to update the CMakeLists.txtconfiguration. For example, if we moved the files to a rpc/ folder like mentioned earlier, it can be done like this:

################# create target #######################################################

file(GLOB_RECURSE Headers CONFIGURE_DEPENDS src/*.h src/*.hpp src/*.hxx intermediate/code/*.h intermediate/code/*.hpp intermediate/code/*.hxx rpc/*.h)
file(GLOB_RECURSE Sources CONFIGURE_DEPENDS src/*.cpp src/*.cc intermediate/code/*.cpp rpc/*.cc)
add_library(${CMAKE_PROJECT_NAME} SHARED ${Headers} ${Sources})

#######################################################################################

################# project include-paths ###############################################

target_include_directories(${CMAKE_PROJECT_NAME}
    PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/intermediate/code>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rpc>)

#######################################################################################

Alternatively, you can generate code/config files with plcncli before generating code with protoc. For instance, this fix can be used if the project is compiled with a script:

#!bin/bash

plcncli generate all
protoc --cpp_out=./ file.proto
plcncli build
@martinboers
Copy link
Member

For reference, this zip file contains the source code that causes the parsing error in this case:
exchange.pb.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants