Sample25: Static Library
This article describes the implementation and use of a module of a static TC3 C++ library.
Download
Here you can access the source code for this sample.
- 1. Unpack the downloaded ZIP file.
- 2. Using a Visual Studio with TwinCAT installed, open the project via Open Project ....
- 3. Configure signing for this project by switching on TwinCAT signing with a right-click on Project->Properties->Tc Sign and configure your certificate and password if necessary.
For more information on signing C++ projects, click here. - 4. Select your target system.
- 5. Build the sample (e.g. Build->Build Solution).
- 6. Activate the configuration by clicking on .
- The sample is ready for operation.
Description
The sample contains two projects – the DriverUsingStaticLib project uses the static content of the StaticLib project.
StaticLib:
On the one hand, StaticLib offers the function ComputeSomething in the StaticFunction.h/.cpp.
On the other hand an interface ISampleInterface is defined (see TMCEditor) and implemented in the MultiplicationClass.
DriverUsingStaticLib:
In the CycleUpdate method of the ModuleUsingStaticLib, both the class and the function of StaticLib is used.
Understanding the sample
Follow the steps below to create and use a static library.
Manual recompilation Note that Visual Studio does not automatically recompile the static library during driver development. Do that manually. |
- During development of a C++ project use the TwinCAT Static Library Project template for creating a static library.
- For the following steps use the Edit dialog of VisualStudio, so that afterwards %(AddtitionalIncludeDirectories) or %(AdditionalDependencies) is used.
- 1. In the driver add the directory of the static library to the compiler under Additional Include Directories.
- 2. Add this as an additional dependency for the linker in the driver, which uses the static library. Open the project properties of the driver and add the static library: