Compiling the Cinema 4D R20 C++ SDK Examples

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.

Unzip and Point Cinema 4D to the SDK

  1. Locate sdk.zip in your Cinema 4D installation directory.
    sdk.zip
    • 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.
  2. 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.
  3. Unzip the SDK to C:\sdk.
    0_1536173987690_495ba90d-c201-4579-bc17-c9f49b08df36-image.png
  4. Open Cinema 4D
  5. Edit > Preferences > Plugins
  6. Go to the Plugins tab and add the C:\sdk\plugins folder.
    Plugin Paths
    • 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.

  1. Download the latest version of the C++ Project Tool from developers.maxon.net.
  2. Unzip the project tool to C:\projecttool, ensure that this directory contains the actual project tool and libs, not just another nested folder.
    Project Tool Directory
  3. Open the command prompt (Windows Key, then type "command", and hit enter).
  4. In the command prompt, type
    1. cd c:\projecttool
    2. kernel_app_64bit.exe g_updateproject=C:\sdk
      Project Tool Commands
  5. This should launch the project tool and build a project file for the contents of C:\sdk
    0_1536175506109_288bb334-aa29-4f6e-9457-588fc2794bcd-image.png
  6. Press return.
  7. In your file browser, navigate to and open C:\sdk\plugins\project\. If everything worked as expected, you should now see a file called plugins.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++

  1. In your file browser, navigate to and open C:\sdk\plugins\project\plugins.sln
    0_1536175570674_c5425a94-6593-4cc7-8b36-40c5db6d1b1a-image.png
  2. When you open it, you will likely discover a message that looks like this:
    0_1536182259322_bb81ca2b-29eb-4bac-80ae-74d92cb1b295-image.png
    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.
  3. Hit Cancel and Quit Visual Studio.
  4. Press the Windows key and search for "Visual Studio Installer".
    0_1536182505366_448b3a1d-97e7-443c-a4cc-414397cc0099-image.png
  5. Run the Installer.
  6. Press Yes if prompted to allow changes to your computer.
  7. Click on the Modify button.
    0_1536182561998_05005f68-6da5-4cec-83d0-c058e7e8d3ea-image.png
  8. Click on the Individual Components tab.
  9. Scroll down and check the VC++ 2015.3 v14.00 (v140) toolset for desktop option under the Compilers, Build Tools, and Runtimes header.
    0_1536182632860_0946a6e3-2432-48f0-a431-9a29f6e89ad6-image.png
  10. Click on the Modify button in the lower right.
  11. Allows the installation to complete - it could take a while, this is roughly 5gb of additional downloads.

Build the Project

  1. In your file browser, navigate to and open C:\sdk\plugins\project\plugins.sln
    0_1536175570674_c5425a94-6593-4cc7-8b36-40c5db6d1b1a-image.png
  2. 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).
  3. Go to Build > Build Solution or press F7.
    0_1536182963902_112e69ec-cf7d-4cf5-bbe9-6facf3772d8c-image.png
    • 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.
  4. Assuming everything went correctly, you should see:
    0_1536183170361_a3cddf0f-f6ad-4641-8f80-33b9098c5213-image.png
    • 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

  1. Open Cinema 4D R20
  2. Plugins > Cinema 4D SDK
    0_1536183347392_0ba858e6-4588-46e4-99c3-c39eb0b42974-image.png

Congratulations! You've successfully compiled the Cinema 4D SDK Example Plugins!

Hello and thanks for your elaborate post.

I just want to add that - as you said - one should use Visual Studio 2015 for C++ plugin development. When you re-use the Project Tool it might overwrite your manually changed project files.

Also you can start Cinema 4D from within Visual Studio. You can also define the plugin path by settting the g_additionalModulePath command line argument.

You find information on this in the "Development for Microsoft Windows" manual.

best wishes,
Sebastian

You probably want to add that all projects (including frameworks) have to be set to use C++17 language when using 2017 with platform toolset 141, otherwise there will be compiler errors.
So, no need to install the older platform toolset. 🙂

thank you for this 🙂 it really helped me to get things going again

Thank you for the guide. But is there a way to proceed without downloading 5GB? or is there a way to download the 5GB installer so I can reuse it again.

I'm using R21.

Hi @bentraje, I'm not sure of which 5Gb you are talking about, the cinema SDK is only few mb so I guess you are speaking about Visual Studio. If that the case yes you need visual studio with the C++ component to compile.

Cheers,
Maxime.

@m_adam
Thanks. You are right. It didn't exceed 5GB. I guess 5GB is when it is uncompressed.
I was able to build the plug-ins now.