Some Newbie questions
-
On 07/04/2013 at 09:33, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;---------
Hi to the developer community,
I am a long time Pascal/Delphi coder , but avoided C / C++ all the time as I could get my wanted results easily in Delphi, what I personally find is the best choice for me.
As a 3D artist and also long time C4D user, I would like to program now some ideas (like own created shader solutions etc) and decided therefore to go with C++ to have all the power available.
As we all know, Pascal/Delphi is almost not supported in the 3D-world and so I am standing here with very little knowledge about the C++-world.
I don't want to bother you with silly questions as I will try to get my needed knowledge via tutorials and books, but although I already did read the C++ R14 SDK and searched the web, I am not able to set up a simple 'Hello world'-Plugin with Visual Studio 2010 Express in C++.
Here is the problem with R14:
My Visual Studio 2010 setup for compiling the R14-'cinema4dsdk' Sample-Plugins in 64 bit is correct and compiles without faults (I added the missing linker path as decribed here in the forum in the linker/general .. additional libraries -> added c:\program files\microsoft sdks\windows\v7.1\lib\x64). The Plugins are then shown correctly in the C4D-Plugin-menue.
So far, so good.
But when I now try to use the compiled 'cinema4dsdk' Sample-Folder as a base for my own plugins (f.e. a simple 'Hello world' output), the problems begin.
I tried to go the way described here: http://www.andrewnoske.com/wiki/index.php?title=Cinema_4D\_-\_C%2B%2B_plugins to set up a new 64 bit plugin based on the 64-bit release-compiled 'cinema4dsdk'-example.
No luck.
Now I copied the whole 'cinema4dsdk'-Folder, renamed it in MyCPlugins, opened the cinema4dsdk.vcxproj in VS2010, renamed the project there to mycplugin and compiled with no other changes, what also worked.
Now I closed VS2010, went to the MyCPlugins-directory and renamed the cinema4dsdk.vcxproj in mycplugin.vcxproj. Then I stated VS2010 and opened mycplugin.vcxproj.
First surprise, the _api is gone now in the projekt-map explorer.
Now I deleted everything but the main.cpp both in the \source-folder as well as in the Project-map-tree.
I wrote this in main.cpp:
*****
#define ID_HELLOTEST 1000001
// unique ID for this plugin#include "c4d.h"
//########################################
class HelloWorldTest : public CommandData // data class for creating new commands (previously known as "menu plugins")
{
public:
virtual Bool Execute(BaseDocument *doc)
{
MessageDialog("Hello World"); // simple popup message
GePrint("This is my first plugin"); // output to C4D's "Console window"
return TRUE;
}
};//########################################
Bool PluginStart(void) // the main function C4D calls to begin your plugin (think of it as main)
{
return RegisterCommandPlugin( ID_HELLOTEST,"Hello World",
0,NULL,String("Hello World"),
gNew HelloWorldTest );
// registers a command plugin with C4D
// (ie: the class to execute when user selects "Hello World" under the Plugin menu)
}void PluginEnd(void) // called when the plugin is unloaded from C4D
{
}Bool PluginMessage(LONG id, void *data) // allows you to receive plugin messages from C4D or other plugins
{
return TRUE;
}
*****
The compilation failed (see below)
Then I used the simpliest code:
*****
// This is the main file of the CINEMA 4D SDK
//
// When you create your own projects much less code is needed (this file is rather long as it tries to show all kinds of different uses).
//
// An empty project simply looks like this:
//
#include "c4d.h"
//
Bool PluginStart(void)
{
// ...do or register something...
return TRUE;
}
//
void PluginEnd(void)
{
}
//
Bool PluginMessage(LONG id, void *data)
{
return FALSE;
}
//
*****
When I try to compile (no other changes are made), the linker always prompts an error:
1>LINK : fatal error LNK1104: Datei "D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api_lib\_api_Win32_Debug.lib" kann nicht geöffnet werden.
When I take a look at the Project-Settings -> Linker -> Befehlszeile, I have this in the compiled original cinema4dsdk.vcxproj:
**
/OUT:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\cinema4dsdk\cinema4dsdk.cdl64" /NOLOGO /LIBPATH:"c:\program files\microsoft sdks\windows\v7.1\lib\x64" /DLL "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "D:\Programme\Grafik\MAXON\CINEMA 4D R14 \resource\_api_lib\_api_x64_Release.lib" /NODEFAULTLIB:"LIBCD" /MANIFEST:NO /ManifestFile:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\cinema4dsdk\obj\cinema4dsdk\x64_Release\cinema4dsdk.cdl64.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\cinema4dsdk\obj\cinema4dsdk_x64_Release.pdb" /OPT:REF /PGD:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\cinema4dsdk\cinema4dsdk.pgd" /TLBID:1 /DYNAMICBASE /FIXED:NO /NXCOMPAT /IMPLIB:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\cinema4dsdk\obj\cinema4dsdk\x64_Release\cinema4dsdk.cdl64.lib" /MACHINE:X64 /ERRORREPORT:QUEUE
**
and after simply renaming the file in mycplugin.vcxproj, I have this when I reopen it in VS2010:
**
/OUT:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\MyCPlugins\mycplugin.cdl" /INCREMENTAL /NOLOGO /DLL "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "D:\Programme\Grafik\MAXON\CINEMA 4D R14 \resource\_api_lib\_api_Win32_Debug.lib" /NODEFAULTLIB:"LIBCD" /MANIFEST:NO /ManifestFile:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\MyCPlugins\obj\mycplugin\Win32_Debug\mycplugin.cdl.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\MyCPlugins\obj\mycplugin_Win32_Debug.pdb" /PGD:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\MyCPlugins\mycplugin.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\MyCPlugins\obj\mycplugin\Win32_Debug\mycplugin.cdl.lib" /MACHINE:X86 /ERRORREPORT:QUEUE
**
I have set everything to 'Release' and 'X64' wherever I could find it, but always the same problem.
But when I rename the mycplugin.vcxproj back to cinema4dsdk.vcxproj and reopen it in VS2010, the _api is back again and the compilation works flawless.
I am frustrated.
The Delphi compiler can be anoying sometimes, but the C++ enviroment is hell.
I have no idea what do I wrong or how do I set up this correctly.
Does anyone have a working, valid for the current R14 SDK step-by-step description for setting up a 'blanko'-Plugin-Project as a start for getting my own code correctly compiled ?
Thanks for any solutions. -
On 07/04/2013 at 11:52, xxxxxxxx wrote:
There's a couple of places to look for some help in creating your first VS plugin.
-The official way to do it:
http://c4dprogramming.wordpress.com/2012/09/30/creating-a-new-plugin-project-in-visual-studio-The non-official way to do it:
http://www.microbion.co.uk/graphics/c4d/create_plugins1.htmI personally prefer Steve's non-official, no API files, way of doing it. Because I like to save my entire solutions. And including the API just makes the files much larger.
But that's just my personal preference.-ScottA
-
On 07/04/2013 at 12:38, xxxxxxxx wrote:
Hello Scott,
I will immediately check this out.
Thanks a lot. -
On 07/04/2013 at 13:57, xxxxxxxx wrote:
OK, found everything so far on Microbions tutorial, except this:
7.
rather than recompile the _api project from the cinema4dsdk example plugin (because you already did that when building the example, and it's a waste of time to do it again) you're going to link to the compiled API library, so you need to tell the linker where that is. In Linker\General, set Additional Library Directories to the folder which contains the library file _api_Win32_Debug.lib (this is normally the path Cinema 4D Rxx\resource\_api_lib)
I have a 64bit PC , and in my R14 _api_lib-Folder are only the files _api_x64_Debug.lib and _api_x64_Release.lib, but no _api_Win32_Debug.lib.
Where do I get it ? -
On 07/04/2013 at 14:07, xxxxxxxx wrote:
Uff, OK, got it.
Normally I would erase the previous post, but in case another Newbie is lost like I am currently, I write my problems and solutions here to make life much more easy for beginners.
The solultion for the missing _api_Win32_Debug.lib is, that before doing anything with preparing a structure for own plugins, one has to compile the 'cinema4dsdk.vcxproj' 4 times :- Debug win32
- Release Win32
- Debug X64
- Release X64
The targets have to be set in Build -> Configuration Manager for -api and cinema4dsdk.
if you get an error with 64 bit like:
LINK : I:\Program Files\MAXON\CINEMA 4D R14 Demo\plugins\cinema4dsdk\cinema4dsdk.cdl64 not found or not built by the last incremental link; performing full link
2>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
, then do this:
in the linker/general .. additional libraries
add c:\program files\microsoft sdks\windows\v7.1\lib\x64I also changed the Plattformtoolset (Property-Manager of the project file (Rightclick project-file in Project-explorer, choose Properties),then tab 'Configuration -> Common') from v100 to Windows7.1SDK
After compiling 4 times, lately all necessary files are located in the R14 resource-folders.
Is that written anywhere ?
I am feeling like Indiana Jones, solving hidden secrets while a giant sphere is rolling down on me.........
-
On 07/04/2013 at 14:26, xxxxxxxx wrote:
Exactly. The way that the Cinema 4D project is set up, you can't build all of the Solution Configurations and Platforms in one go. See this StackOverflow question/answer for a way to make this possible for your own projects:
http://stackoverflow.com/questions/6444493/build-multiple-configurations-of-a-project-in-a-single-build-operation-in-visualDon't lose your hat and the pistol is easier than the sword (?)
-
On 07/04/2013 at 14:56, xxxxxxxx wrote:
I feel your pain.
It wasn't that long ago that I launched V.S. for the very first time. And I had a very hard time figuring out how to get everything set up too. Even with Steve's site as a guide.This is my own version of the information found on Steve's site.
It's written in a different way that makes more sense to my brain. Maybe it will help you out too:Instructions: -Create your plugin with the skeleton folder structure inside of it *** Make sure you have your main.cpp file set up. And in the source folder *** *** The main.cpp file is used to load the api .h files. As well as register your plugins*** -Put your plugin folder with the basic file structure in the C4D plugins folder -Create a new emtpy C++ project(uncheck make directory. And select the C4D plugins folder(not your new plugin folder) as the source) -Name your project the same name as your new plugin folder so it will write the solution into that folder properly -Add the Debug & Release property sheets to the project(view->otherwindows->propertymanager) by right clicking them and choose: CINEMA 4D R12\resource\_api_lib\ Then adding these files to the proper project folders: Debug | Win 32 = DebugWin32.props Debug | Win 32 = ReleaseWin32.props -For C4D R13 and later: Go into the cinema4dsdk folder which is found in the "plugins" folder. Then add the "projectsettings.props" file just like you added the DebugWin32.props & ReleaseWin32.props files. NOTE: MAXON suggests a different way to do this using macros instead. -Now right click the source folder and choose Add Existing Project Add your main.cpp file as well as any other .cpp or .h files files you might also have in your project VisualStudio will automatically load all of the .h files from the api into your solution In configuration properties General -Set Target Extension to .cdl -Set Configuration type to Dynamic Library.dll In configuration properties Debugging -Set Command to: C:\Program Files\MAXON\CINEMA 4D R12\CINEMA 4D.exe or whichever .exe version you'll launch with the debugger In configuration properties Linker -In General->Set Output File to the same name as your project and with the extension: .cdl -In General->Set Additional Library Directories to: C:\Program Files\MAXON\CINEMA 4D R12\resource\_api_lib -In Input-> Additional Dependencies. Add this to the list: _api_Win32_Debug.lib -in Advanced-> change Randomized Base Address to Disable Image Randomization (DYNAMICBASE:NO) DONE with 32 bit setup!! To set up 64 bit compiling we have more work to do: -From the top menu. Click the solution platforms dropdown and select Configuration Manager -On the right drop down list. Select "New" from the options.Then select x64 -Next be sure to also enable the BUild option for this new platform -Add the Debug & Release property sheets to the project just like you did with the 32 bit platform setup above -This time select these files from the _api_lib folder: Debug | Win 64 = DebugWin64.props Debug | Win 64 = ReleaseWin64.props Right click on the project in the solution window and select properties Set up the various options the same way you set up the 32 bit options with two exceptions: -In Linker->General: Set Output File to the same name as your project and with the extension: .cdl64 -In Linker Input->Additional Dependencies. Add this to the list: _api_x64_Debug.lib DONE with 32&64 bit setups!! #################### This is not needed...But if you want to add the api here's how to do it################################# ############################################################################################################################# -Right click the soultion and choose Add Existing Project: C:\Program Files\MAXON\CINEMA 4D R12\resource\_api_lib\_api.vcxproj -Right click the soultion and choose Project Dependancies then select your plugin from the drop down list -Make your plugin dependant on the api by enabling the checkmark -Add the existing source files to the source folder if you have them(main, etc.) #############################################################################################################################
-ScottA
-
On 07/04/2013 at 14:56, xxxxxxxx wrote:
@Robert: Yes, but the way of the sword is an art.
And like Musashi said:
"You must understand that there is more than one path to the top of the mountain"
― Miyamoto Musashi, A Book of Five Rings: The Classic Guide to Strategy
__
and
__
"from one thing, know ten thousand things"
― Miyamoto Musashi, The Book of Five Rings: Miyamoto Musashi
__
sou desu ne
@Scott: thank you -
On 07/04/2013 at 15:12, xxxxxxxx wrote:
hai, sou desu!
-
On 07/04/2013 at 15:22, xxxxxxxx wrote:
Maybe the moderators can pin this thread or ScottA's description on a top-level so Newbies like me can find a quick entry to a working Compiler-setup ?
-
On 07/04/2013 at 15:30, xxxxxxxx wrote:
That's very kind.
But as they say in jolly old England: "Not Bloody Likely".This is not the "official" way they want us to set things up in VS.
So I don't think it's something they would want to promote.The blog that I linked to does a pretty good job of explaining how to do the "official" set up. With images to help see it in action.
But I must confess. I've never actually tried it that way yet.-ScottA
-
On 07/04/2013 at 15:45, xxxxxxxx wrote:
Problem:
I thought I had set it all right as ScottA described, but when I try to build a simple Hello-World code, I get this error:
1>------ Neues Erstellen gestartet: Projekt: MyCPlugin, Konfiguration: Release x64 ------
1> main.cpp
1>d:\programme\grafik\maxon\cinema 4d r14\plugins\mycplugin\source\main.cpp(34) : fatal error C1083: Cannot open include file: 'c4d.h': No such file or directory
========== Alles neu erstellen: 0 erfolgreich, Fehler bei 1, 0 übersprungen ==========
Seems that I missed setting a path, but where ?
I tried to add 'D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api' to the additional libraries in the Linker-> Common Tab, but always the same error message -
On 07/04/2013 at 16:09, xxxxxxxx wrote:
There's two places under Linker to set up the dependencies.
Linker- >General->Additional Library Directories:
D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api_libLinker- >General->Additional Dependencies:
_api_x64_Debug.lib
NOTE: for the 32 bit build version this will be:_api_Win32_Debug.libAlso make sure you have a folder in your solution called External Dependencies.
And it has the c4d.h file in it amongst the various .h files.
If that's not there you did something wrong and need to start over again.I also strongly suggest focusing on just getting a 32 bit version to compile first.
Once you can compile 32 bit version. Then you can try to set up the 64 bit version.-ScottA
-Also
There are two folders named: _api & _api_lib
The one you want to use is: _api_lib -
On 07/04/2013 at 16:27, xxxxxxxx wrote:
Oh yeah. One other thing.
Make sure C4D is closed before you try to compile your plugin.
I can't tell you how many times I got caught on that one when I first started out. !Embarrassed
[URL-REMOVED]-ScottA
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 07/04/2013 at 16:30, xxxxxxxx wrote:
Hi Scott,
no, I don't have such a folder called External Dependencies in my new Plugin-solution.
Maybe I understood something wrong.
I have added now additionally the path:
D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api
to the **Linker- >General->Additional Library Directories **so there is now written in that line:
D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api_lib;D:\Programme\Grafik\MAXON\CINEMA 4D R14\resource\_api
f.e. for the Debug Win32, I have added in the Linker- >Input->Additional Dependencies:
_api_Win32_Debug.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
I made all steps before as described by you and Microbion and added also manually a folder 'Debug' with the files DebugWin32.props and DebugWin64.props copied from the cinema4dsdk-Folder and added manually the file projectsettings.props
What could be wrong then ? -
On 07/04/2013 at 17:10, xxxxxxxx wrote:
@Scott:
OK, I started again from scratch, this time exactly how you described.
I missunderstood some phrases in your text concerning the DebugWin32.props and DebugWin64.props procedure, but I had already done the right thing according to micobions tutorial.
Anyway, now a complete new try.
This time I have the External depencies folder listed in the project.
I only made the setup so far for Debug Win32, but when trying to build I get this time:
1>------ Neues Erstellen gestartet: Projekt: mycplugin, Konfiguration: Debug Win32 ------
1> main.cpp
1>LINK : fatal error LNK1104: Datei "_api_Win32_Debug.lib" kann nicht geöffnet werden.
========== Alles neu erstellen: 0 erfolgreich, Fehler bei 1, 0 übersprungen ==========
I'll finish all steps and see what the linker says then.
Edit: Oops, wrong path to the _api_lib, I copied it from your text.
Now, with the right path, the compiler runs through and I see:
1>------ Neues Erstellen gestartet: Projekt: mycplugin, Konfiguration: Debug Win32 ------
1> main.cpp
1> Bibliothek "D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\mycplugin\obj\mycplugin\Win32_Debug\mycplugin.cdl.lib" und Objekt "D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\mycplugin\obj\mycplugin\Win32_Debug\mycplugin.cdl.exp" werden erstellt.
1> mycplugin.vcxproj -> D:\Programme\Grafik\MAXON\CINEMA 4D R14\Plugins\mycplugin\mycplugin.cdl
========== Alles neu erstellen: 1 erfolgreich, Fehler bei 0, 0 übersprungen ==========
Hip Hip, Hurah
Now, I can finish the other settings.
Thanks, Scott, your tutorial finally made it. -
On 07/04/2013 at 17:19, xxxxxxxx wrote:
It's definitely tricky. And you have to get everything just right and in the proper sequence.
It took me several tries to get it working myself.Note:
The main.cpp file works in combo with the projectsettings.props, DebugWin32.props and ReleaseWin32.props files to automatically create that folder and then loads the proper api .h files into it. So it a critical thing to get right.Make it easier on yourself.
Only try to create a 32 bit Debug version at this point. Don't even bother with setting up the 32 bit Release options at this point. You can always add those other versions later on after you get it working.Make sure you have the proper source files before you even get started.
-Do you have a main.cpp file with code in it that registers your HelloWorld plugin?
If not. Your VS setup will not automatically add the External Dependencies folder with the needed api .h files in it. And you won't be able to build the project.If all else fails and you just can't get it working. And you get frustrated and just want to move on and make a very simple plugin.
You can always make plugins right inside the compiled SDK. It's much easier than trying to build a stand alone plugin framework. A lot of people start off making their first C++ plugin this way.I have a video tutorial about that here:https://sites.google.com/site/scottayersmedia/scripting
It's aimed at Coffee users trying to switch over to C++ and VS.
It's for R12. But I think most of it is still relevant.-ScottA
-
On 07/04/2013 at 17:28, xxxxxxxx wrote:
Very nice, I'll check it out tomorrow.
Thanks again for your kind help, otherwise I think I would never have had a chance to set this beast up in the right way.