SOLVED Use of undeclared identifier 'g_resource'

I copied all the files from a shader, from the SDK and adjusted it all to accomodate my code.
But I'm getting the error:

Use of undeclared identifier 'g_resource'

in the code:

switch (id)
		if (!g_resource.Init())
			return false;		// don't start plugin without resource

		return true;

How come it is not declared, since it is completely based in the SDK?

Hi rui,

with regard to the issue reported, it's likely you're not including c4d_resource.h in your project. Since I don't really know how you're proceeding to "migrate" your old plugins to R20, please have a look at both the *microsdk" Project in the SDK example set and to the Plugin Migration section found in our documentation.

I also warmly suggest to have a look at this project on Github which was demoed during DevKitchen 2018 to see what has been adapted and how.

Last but not least, feel free to describe your approach to migrate your plugins since this is not the first thread were issues on migrating are showing up.

Looking forward your input, give best.

I did included the c4d_resource.h and the error disappeared.
I was migrating by simply fixing the errors that appeared inside Xcode, until everything was clear.
But now, I started by duplicating a similar plugin from the sdk and pasting just the parts of the code that belong to my plugin.

My simplest shader plugin is already working 🙂
The problem is with the other shader plugin that is compiling fine, shows up in Cinema 4D R20, but when I choose it, Cinema 4D crashes and I don't have the slightest idea in how to fix it.
It worked fine in all versions from R14 to R19.

Hi Rui and thanks for following-up.

With regard to the crash you're experiencing upon having the plugin compiled, I warmly suggest you to provide as many details as possible:

  • a clear description of the crash
  • the revision were the issue appears
  • the debug stack trace at the crash time
  • a list of other plugins already installed

Without valuable information I can be of no help in identifying the potential cause of the crash and help you get rid of it.

Best, Riccardo

Thank you for the help, Riccardo.
I will provide all that.
I just need to know one thing. The debug stack trace is created by compiling the plugin in what mode? Testing or Profiling?
And the debug stack trace report is in the log file that is produced when the crash occurs?
Sorry, but I never needed to do this, so I really don't know what to do to produce a debug stack trace.

Hi Rui,

no worries, we'll get you there eventually.

Actually you do not need to do anything special. I assume, while developing your plugin you already compile it in debug mode. Then you should already be fine, when running C4D from within Xcode after successful compilation. You may want to add a few command line options to maybe get additional information (see Debugging in the SDK docs or this slightly outdated article about debugging plugins on our blog), but that's not mandatory in a first step. In general, when started from within Xcode your C4D is already running inside the debugger. If now any exception (like something resulting in a crash) occurs, you should be back in the debugger and Xcode should not only show the line in your plugin, where the crash occurred (not implying it's the cause) and you should be able to see the stack trace of that moment in one of Xcodes helper displays.

One more thing to maybe look out for: Xcode also has an output console, where C4D prints some information. Please also check this, maybe there are some hints, what went wrong shortly before the crash.

All of this might already give you a hint. But if not, then maybe we are able to pull some more information form this.


Good news. And... more good news.

The best news are that, after creating a Debug version and running Cinema 4D R20 from XCode, all of a sudden, the plugin started working!!!
I then created a simple build (not a Debug one) and it is still working fine 🙂

The other good news is that I now know how to create a Debug version 🙂