C++
New to programming or C++? We recommend using our Python or C# API instead. Programming in C++ can be challenging because of its complex syntax, complicated build system, manual memory management, and plethora of other advanced concepts. Improper use can often lead to errors that are difficult to diagnose and resolve. We advise against using C++ for new projects unless you have a specific requirement to do so.
Before you begin, please select your operating system below.
Installing the library
For most users, we recommend using the installer below, which includes header files and prebuilt binaries for common platforms. If you encounter any issues with the installer, please contact our customer support team. If the installer does not meet your needs, you can build the library from source using our guide.
Download and run the installer for your platform:
The installer unpacks the header files and binaries to your selected destination.
After installing the library, follow the instructions below to setup and build your project.
Compiling Your Program
Once you have the library installed, it's time to write a program that will make use of it. This section is about configuring your program's build files.
Setting up a new Visual Studio Project
You can save time and skip setting up Visual Studio project by downloading
our exampleThese instructions are for Visual Studio 2019, instructions for other versions may differ.
Filemenu ->New ProjectSelect
C++ Console ApporC++ Desktop App(These steps assume console app); If you don't have these options in the new project list, run the installer for your Visual Studio IDE and add support for C++ development.Click
Next, name your project and select a directory to put it in, then clickCreate.When the project is created, Visual Studio should show you a .cpp file with a
main()function already created to print "Hello World!". To test that your C++ environment is set up, try running this program without changes. If the output window closes too fast to see the results, go to theToolsmenu ->Options->Debuggingand uncheckAutomatically close the console when debugging stops. When you run the program you should now see the "Hello World!" Output.Next we configure the project to use the newer C++ 17 standard and to include files for Zaber Motion Library:
In the Solution Explorer window (
Viewmenu ->Solution Explorerif you don't see it), right-click on your program's project heading and selectProperties.In the table change
C++ Language StandardtoISO C++ 17 Standard (/std:c++17).On the top of the dialog change
ConfigurationtoDebugandPlatformtox64.Under
VC++ Directories, edit theExecutable Directoriesproperty, add a new line and browse to and select thebindirectory of your ZML installation (probablyC:\Program Files\Zaber Motion Library\bin\Debug). If this is aReleasebuild configuration provide a path to the release library file instead (probablyC:\Program Files\Zaber Motion Library\bin\Release).Under
VC++ Directories, edit theInclude Directoriesproperty, add a new line and browse to and select theincludedirectory of your ZML installation (probablyC:\Program Files\Zaber Motion Library\include). You want to select the directory named "include", not any of its subdirectories such as "zaber".Under
VC++ Directories, edit theLibrary Directoriesproperty, add a new line and browse to and select thelibdirectory of your ZML installation (probablyC:\Program Files\Zaber Motion Library\lib\Debug). If this is aReleasebuild configuration provide a path to the release library file instead (probablyC:\Program Files\Zaber Motion Library\lib\Release).Under
Linker->Input, editAdditional Dependenciesand addzaber-motion.lib.This will let you compile the program. To run, the program needs access to the DLLs. You can give the program access by going to
Debuggingand editing theEnvironmentproperty and add the line:PATH=$(ExecutablePath);%PATH%.Note that the steps 4-8 need to be repeated for each configuration you want to build your program for (typically debug and release).
Click
OK.In the top menu bar, set the "Solution Platform" to
x64and save your project.
Qt
You can use the installed library in a Qt project assuming you are using the Visual Studio compiler.
Just add the following lines to your project file (.pro).
CONFIG += c++17
win32 {
CONFIG(debug, debug|release) {
LIBS += -L'C:/Program Files/Zaber Motion Library/bin/Debug'
LIBS += -L'C:/Program Files/Zaber Motion Library/lib/Debug' -lzaber-motion
}
CONFIG(release, debug|release) {
LIBS += -L'C:/Program Files/Zaber Motion Library/bin/Release'
LIBS += -L'C:/Program Files/Zaber Motion Library/lib/Release' -lzaber-motion
}
INCLUDEPATH += 'C:/Program Files/Zaber Motion Library/include'
DEPENDPATH += 'C:/Program Files/Zaber Motion Library/include'
}
MinGW
If you are using the MinGW compiler, the library must be built from source code because the installed binaries are built for Visual Studio. While it is possible to build the library using MinGW compiler, we do not support this use case. You can find more details in our guide.
. If you already have an existing project or require a custom setup, continue with the instructions below.Next Steps
After you've created your project, continue the Getting Started guide by running the example code.
Updating
If you are already using the library and want to update to the latest version (9.2.0), you will have to reinstall the library.