Shared Native Library

Hi,
I’ve installed the new PLCnext Toolchain 2023.0.0 LTS and get errors in VS2019 when creating Shared Native Libraries for target AXCF1152 2023.0.0:
1 Loading LinuxNativePackageerror-1.JPG
ActivityLog.xml:

SetSite failed for package [LinuxNativePackage] Source: 'liblinux.Local' Description: Die Windows-Subsystemshell konnte nicht geöffnet werden

2 Missing MSbuild

Erstellen gestartet...
1>------ Erstellen gestartet: Projekt: SharedNativeLibrary1CSharp, Konfiguration: Debug Any CPU ------
1>- : error : PlcncliException: 
1>- : error : MSBuild was not found. Please use the option --msbuild or set the settings key 'MSBuildPath' or add it to your PATH environment.
1>- : error : 
========== Build: 0 erfolgreich oder aktuell, 1 fehlerhaft, 0 übersprungen ==========

This can be fixed by adding MSbuild to PATH. But then i get 3 Link Language Target

Erstellen gestartet...
1>------ Erstellen gestartet: Projekt: SharedNativeLibrary1CSharp, Konfiguration: Debug Any CPU ------
1>GENERATETASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
1>GENERATETASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
1>GENERATETASK : CMake error : CMake can not determine linker language for target: SharedNativeLibrary1
2>------ Erstellen gestartet: Projekt: SharedNativeLibrary1Cpp, Konfiguration: Debug - all Targets x86 ------
2>BUILDTASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
2>BUILDTASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
2>BUILDTASK : CMake error : CMake can not determine linker language for target: SharedNativeLibrary1
2>Die Erstellung des Projekts "SharedNativeLibrary1Cpp.vcxproj" ist abgeschlossen -- FEHLER.
========== Erstellen: 1 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

Hello Andreas,
the PLCnext Toolchain 2023.0.0 LTS should create the PATH variable during the installation, but the step will be not executed. Please add the PATH for MSBuild manually „C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin“ .
image.png
If the other failures will be not resolved by this fix, please let me know.

BR Eduard

Hello Andreas,
additional Explanation/Info to the following Message: 1 Loading LinuxNativePackage not loaded
→ I assume you don’t installed this Package. The Package can be used for building/compressing the App’s for PLCnext Targets on WinOS in SquashFS format. This format will be supported by Linux System and the Package provides the feature to build/create it on WinOS.
If you do not need this feature/package, you can answer „No“ to the question in the user window to avoid the showing again.

Hello Eduard,
if I manually add MSBuild to the PATH enviroment variable i get these errors

Erstellen gestartet...
1>------ Erstellen gestartet: Projekt: SharedNativeLibrary1CSharp, Konfiguration: Debug Any CPU ------
1>GENERATETASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
1>GENERATETASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
1>GENERATETASK : CMake error : CMake can not determine linker language for target: SharedNativeLibrary1
2>------ Erstellen gestartet: Projekt: SharedNativeLibrary1Cpp, Konfiguration: Debug - all Targets x86 ------
2>BUILDTASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
2>BUILDTASK : CMake error : Cannot determine link language for target "SharedNativeLibrary1".
2>BUILDTASK : CMake error : CMake can not determine linker language for target: SharedNativeLibrary1
2>Die Erstellung des Projekts "SharedNativeLibrary1Cpp.vcxproj" ist abgeschlossen -- FEHLER.
========== Erstellen: 1 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

I also got those errors when trying to build a empty project. After following the procedure in the README file and adding a Function Block to the project, the project was able to build ok.

I also got those errors when trying to build a empty project. After following the procedure in the README file and adding a Function Block to the project, the project was able to build ok.</p>

Sorry my fault. Now it works! Many thanks

The procedure is a little more complicated than other project types, so I am currently planning a Makers Blog post with a „getting started“ example that should help others who want to try developing functions and/or function blocks in C++.

Yes, you’re right.
Unfortunately I have some new issues:
The generated *.cpp files (in directory cpp/src
1. ) are not listed in the cpp project.
2. If further Native Function Blocks are added by „Add new Item“ some errors occur like
error G22D29BD3: ‚SharedNativeLibrary1::NativeFunctionBlock2‘ has not been declared
To solve this issue, I need to delete the cpp/intermediate and cpp/src directories (whereby my native code is deleted aswell, or I need to copy paste them)
I don’t think that’s the way it was planned, right?

The second issue has already been raised internally and is awaiting an answer from the developers.
The first issue is not so critical, I think - it’s possible to see the .cpp file that is generated using a different filter in the Solution window.

A new page has now been added to the PLCnext Info Center, which includes all the information I was going to put into my (now unecessary) Makers Blog:
C++ functions and functions blocks This feature is based on Shared Native Libraries and is a combination of C++ implementation and C# wrapper. The PLCnext toolchain supports this with a Microsoft® Visual Studio® IDE template, or on the command line with the PLCnext CLI. I will post the answer to the question about multiple POUs, when I have it.

The info-page is awesome! Thank you!
FYI:
For enumerations, respective *-cli.cpp files generated as well, but they are not needed (at least in my case). So my project consists of more of the „empty“ files than the actual code.

[Native] 
[Enumeration] 
public enum MyType { Type1, Type2 }                                               
MyType-cli.cpp:
// ClientType native assembly code template.
// PHOENIX CONTACT Software embedded CLR native assembly builder tool generated source file.
// use this file to implement your own native code
#include "eclr.h"
#include "MyLibrary.h"
// class MyLibrary.MyType implementation

The procedure in the PLCnext Info Center also helps with the question about multiple POUs.
To add a new POU:

                              * Add the new POU to the C# project.
                              * Select the "Generate" command to create the .cpp file for the POU in the C++ project.
                              * In the C# project, changes were automatically made to the _< projectname>-template32.h_ and _< projectname>-template64.h_ files (located in the CLI folder). In the C++ project, manually update the files _< projectname>-cli32.h_ and _< projectname>-cli64.h_ with the changes.