I am creating a file which has #ifdef directives. I need this as I want to make a file which can be used by PLCnext and also by other C++ compilers/projects.
When I run plcncli generate code , it does not respect the #ifdef directives and ignores them entirely (as if they were never there). For example:
After running this through plcncli generate code , I get the error:
The fields ____ of the type ____ are ambiguous. In types used for ports only non-ambiguous fields should exist.
This means all eight lines of variables were parsed. If the directives were followed, this should be impossible as only one set of these would be included. Can you please suggest a fix for this, or if there is something I am missing?
Kind Regards,
Joshua
Hello Joshua,
I would like to recommend to use the latest „PLCnext Toolchain 2023.0.0 LTS“. The #ifdef directives are the part of SLN (Shared native Library) template, during compilation I don’t get any errors.
Here is the code part in header file:
#pragma once
#ifndef PLATFORM_DATAMODEL_P64_DEFINED
#include „TestPLCnCLI2023-cli32.h“
#else
#include „TestPLCnCLI2023-cli64.h“
#endif
I hope it helps, if not please let me know.
BR Eduard
Hi Eduard,
I can confirm that the same occurs with the 2023.0 toolchain (I was using 2022.6 before).
For more context, I have an external header file that has the code above. I include this header in the realtime program.
Can you please try using plcncli new program to create a new program and add variables similar to those above in an external header?
Kind Regards,
Joshua
Hello Joshua,
please see the example below, I can’t see any errors:
BR Eduard
Hi Eduard,
Your code example is using C#.
Can you please try using C++ which uses #ifdef #ifndef ?
Kind Regards,
Joshua