Compiling the Cinema 4D R20 C++ SDK Examples
Background
I've been developing Cinema 4D plugins using the Python API for a long time, and have attempted (but often struggled) to do development with Cinema 4D's C++ API. One of my biggest stumbling blocks was just getting the example plugins to compile. So, in this post, I'm going to try and catalog the steps I've taken to get this working.
Reference
I'm making extensive use of the Cinema 4D C++ SDK Documentation, and it should be seen as the definitive source of the information I'm providing in a simplified format here. Specifically, I found the following pages/articles quite helpful:
Disclaimer
I am by no means an expert, and I will likely not be approaching things in the best/most correct way. If you know of a better way to do something, or if I'm sharing incorrect info, please correct me!
Pre-Requisites
Modern programming relies on a complex of interconnected tools to do anything mildly useful. Some things that work great with one version of a tool, just won't work in the next version. So, I can only promise that this works with the exact setup I'm running, and if you find a workaround due to a difference in your setup, please post it.
- Cinema 4D R20 SP1
- Microsoft Windows 10 (I'm sure this can be done on a Mac, I just don't know how yet).
- Microsoft Visual Studio Community 2017
- Get a HelloWorld C++ Console Application working to verify Visual Studio is working period.
- Note: It seems like VS 2015 is what's officially supported/required by the Maxon C++ SDK, so that might be the better choice but will differ from my instructions below.
Unzip and Point Cinema 4D to the SDK
- Locate
sdk.zip
in your Cinema 4D installation directory.
- Note: This is different from the SDK Examples GitHub Repo as it includes a critical
frameworks
directory. - If you don't have
sdk.zip
I think the only way to get it is to reinstall Cinema 4D. - I recommend keeping a backup of this .zip file somewhere.
- Note: This is different from the SDK Examples GitHub Repo as it includes a critical
- Duplicate
sdk.zip
into a path that is easy to access via terminal. e.g.C:\sdk.zip
- I'm duplicating the .zip to avoid accidentally deleting it as it's hard to recover a clean version without a reinstall of C4D.
- You may need admin rights on your machine to do this.
- Unzip the SDK to
C:\sdk
.
- Open Cinema 4D
- Edit > Preferences > Plugins
- Go to the Plugins tab and add the
C:\sdk\plugins
folder.
- Unlike previous version of Cinema 4D, R20 lets you point to multiple plugins directory, making development much simpler.
If you restart Cinema 4D at this point, you may be disappointed to discover that no new plugins have shown up. That's because we need to...
Generate a Visual Studio Project
In previous versions of C4D you would have to have a keen understanding of Visual Studio to setup a project from scratch, or the patience to duplicate an existing working project and then rip out everything that doesn't do what you need. Maxon has provided a really great new tool that allows you to build a working Visual Studio project file from a single source directory so long as it includes a specifically named and formatted .txt
file.
- Download the latest version of the
C++ Project Tool
[URL-REMOVED] from developers.maxon.net. - Unzip the project tool to
C:\projecttool
, ensure that this directory contains the actual project tool and libs, not just another nested folder.
- Open the command prompt (Windows Key, then type "command", and hit enter).
- In the command prompt, type
cd c:\projecttool
kernel_app_64bit.exe g_updateproject=C:\sdk
- This should launch the project tool and build a project file for the contents of
C:\sdk
- Press return.
- In your file browser, navigate to and open
C:\sdk\plugins\project\
. If everything worked as expected, you should now see a file calledplugins.sln
You've now created a Visual Studio project file that could be used to compile your project. But there's still more we have to do.
Add v140 Support to VC++
- In your file browser, navigate to and open
C:\sdk\plugins\project\plugins.sln
- When you open it, you will likely discover a message that looks like this:
This indicates that the project file doesn't match the latest and greatest from Microsoft. That's because the project was built for Visual Studio 2015, and we're using Visual Studio 2017. We'll need to modify our Visual Studio installation. - Hit Cancel and Quit Visual Studio.
- Press the Windows key and search for "Visual Studio Installer".
- Run the Installer.
- Press
Yes
if prompted to allow changes to your computer. - Click on the
Modify
button.
- Click on the
Individual Components
tab. - Scroll down and check the
VC++ 2015.3 v14.00 (v140) toolset for desktop
option under the Compilers, Build Tools, and Runtimes header.
- Click on the
Modify
button in the lower right. - Allows the installation to complete - it could take a while, this is roughly 5gb of additional downloads.
Build the Project
- In your file browser, navigate to and open
C:\sdk\plugins\project\plugins.sln
- Visual Studio should re-open, only this time you won't see the window asking if you want to upgrade the project (if you do, select the options for both dropdowns that say something like Leave as Is).
- Go to Build > Build Solution or press F7.
- A bunch of text should appear in the Console and update.
- The build process will likely take a few minutes, as VC++ is compiling the whole C4D SDK, future builds will likely be much quicker as only modified files will need to be completely rebuilt.
- Assuming everything went correctly, you should see:
- If you encounter errors, read them carefully and Google liberally. That's how I was eventually able to get it all working on my end (adding v140 support was the issue with my setup).
Verify the Plugins Were Compiled
- Open Cinema 4D R20
- Plugins > Cinema 4D SDK
Congratulations! You've successfully compiled the Cinema 4D SDK Example Plugins!
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.