Libcurl
-
On 25/08/2016 at 13:41, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14
Platform: Windows ;
Language(s) : C++ ;---------
I've recently been trying to create a plugin in Visual Studio 2010 that utilizes Curl and have been having trouble with the 64 bit version. For my plugin I downloaded curl from https://curl.haxx.se/.Following the instructions inside BUILD.WINDOWS.txt I built curl in the Visual Studio Command Prompt using: nmake /f Makefile.vc mode=dll.
Going through the suggestions on this thread I did the following
-Placing libcurl.dll inside the VS project's Debug and Release folders
Inside the project's properties
-Set the paths for "Include Directories" and "Library Directories" to the curl folders.
-Place libcurl.lib inside the "Additional Dependencies" for Linker->Input.Using these I compiled the 32 bit version of my plugin within VS successfully.
I then used the instructions listed in BUILD.WINDOWS.txt to build a 64 bit curl using: nmake /f Makefile.vc mode=dll MACHINE=x64
I switched the above suggestions to point at the 64 bit curl paths, and place the new libcurl.dll inside the two folders. When I compile the 64 bit version of my plugin in VS it finished without errors.The problem comes in when I open Cinema and my plugin isn't included in the plugin drop down.I'm not sure if I didn't build the 64 bit curl correctly or is the 64 bit curl gotten in a completely different way. Any help would be appreciated because I'm stumped.
Peter S.
-
On 26/08/2016 at 07:25, xxxxxxxx wrote:
Typically a .dll library will throw errors in VS. Or when you launch C4D if you did something wrong.
It sounds more like you made a mistake in making the plugin itself.
I would remove the curl code and see if the plugin shows up and executes in C4D.-ScottA
-
On 26/08/2016 at 07:51, xxxxxxxx wrote:
I highly recommend linking libraries static as much as possible. Cinema 4D does not provide you with
a good way of using external DLLs/dylibs from your plugin and you need to place them in the C4D
installation directory via an installer, use dlopen() and manually read DLL member addresses or use a
workaround with an additional plugin that updates the PATH/DYLD_LIBRARY_PATH before your real
plugin is loaded.Cheers,
Niklas -
On 26/08/2016 at 08:51, xxxxxxxx wrote:
Hi Peter,
welcome to the Plugin Café forums
Unfortunately I need to leave this question for our community. We (MAXON's SDK Team) usually support only the latest version of Cinema's SDK and we are lacking the resources to support third party libraries. Sorry.
Any way, this will be hard to diagnose remotely.
In order to make it easier for the community, you should probably provide some more information:
- Any error messages in the console?
- Did you try to instrument your code (e.g. printing to the console in PluginStart()), to see where the plugin fails (or if it doesn't even get into PluginStart())?
- How are you linking the Curl library (statically or dynamically)?
- and probably all other details I forgot to list here -
On 26/08/2016 at 09:02, xxxxxxxx wrote:
In this case. libcurl has no rules against static linking. So that's probably the best choice.
But sometimes you cannot use static linking because it's against the terms of use for a library.
Qt for example wants you to include the .dll's in your projects. It's how they advertise their product.FYI,
We can load .dll's dynamically in the main.cpp file of the plugin.
That way you can put the .dll in your plugin's folder, and the user will never need to manually place it in the main C4D folder.
I use it all of the time. But I'm not sure if it works with Macs?-ScottA
-
On 26/08/2016 at 10:10, xxxxxxxx wrote:
Thanks for the quick responses.
Per your suggestion Scott I went into the plugin and commented out all of the code that referenced Curl. When I compiled this version of the plugin it would appear in the plugin dropdown and run correctly. While slowly uncommenting out the code that referenced Curl I found the exact line that prevented it from appearing in the dropdown.
CURL *curl; FILE fp; CURLcode res; //This line causes the plugin to not appear curl = curl_easy_init();
When the plugin doesn't appear I don't get any errors in the console window.
I placed several prints inside of PluginStart() and none of these were printed when I reopened Cinema after recompiling.
I statically linked the Curl library.Peter S.
-
On 26/08/2016 at 13:59, xxxxxxxx wrote:
Since you're using VS2010 and probably an older version of libcurl. I don't know if I can really help that much. Because I'm using VS2013 and libcurl v7.50.1.
But here is how I compile the library statically:
Installation instructions for the Debug x64 static version of libcurl -Unzip to c:\curl -You need to use the VisualStudio (x86 or x64)command console...not the windows console!!! The VS x86 command prompt automatically compiles curl x86 The VS x64 command prompt automatically compiles curl x64 In the prompt. Go to this folder: c:\curl\winbuild I used this in the console to build it: nmake /f Makefile.vc mode=static DEBUG=yes rtlibcfg=static This is how I set up the Visual Studio properties to use it: C/C++ General Additional Include Directories: add this: C:\curl\builds\libcurl-vc-x64-debug-static-ipv6-sspi-winssl\include\curl C/C++ Preprocessor: add this: CURL_STATICLIB Linker General Additional Library Directories: add this: C:\curl\builds\libcurl-vc-x64-debug-static-ipv6-sspi-winssl\lib Input Additional Dependencies: add this: libcurl_a_debug.lib
And here is an example of using the library in a C4D CommandData plugin:
#include <stdio.h> #include <curl.h> #include <iostream> #include <string> #include "c4d.h" #include "c4d_symbols.h" #define PLUGIN_ID 1024309 static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string* )userp)->append((char* )contents, size * nmemb); return size *nmemb; } class SimplePlugin : public CommandData { public: SimplePlugin(); void forewardFacingPoints(BaseDocument *doc, PolygonObject *pObj, BaseDraw *bd, GeDynamicArray<Vector> *ssp); virtual Bool Execute(BaseDocument *doc); }; SimplePlugin::SimplePlugin() { //not used in this example } Bool SimplePlugin::Execute(BaseDocument *doc) { CURL *curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/robots.txt"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); res = curl_easy_perform(curl); curl_easy_cleanup(curl); std::cout << readBuffer << std::endl; String convertedToC4D = readBuffer.c_str(); GePrint(convertedToC4D); } EventAdd(); return true; } Bool RegisterSimplePlugin() { return RegisterCommandPlugin(PLUGIN_ID, GeLoadString(IDS_My_Simple_Plugin), 0, NULL, String("Help text Goes here"), gNew SimplePlugin); }
-ScottA
-
On 31/08/2016 at 13:33, xxxxxxxx wrote:
Thanks a lot for the directions Scott, using them I was able to successfully compile a 64 bit version of my code in VS 2012 & 2013.
Going back to VS 2010, do you know if it is possible to build Curl for VS 2010 using the x64 command console from VS 2012 or 2013, or does it need to be from a X64 command console from VS 2010? Secondarily do you know if I need an earlier version of curl to be able to build a VS 2010 compatible version?
Once again thanks for the directions, helped a bunch.
Peter. S
-
On 31/08/2016 at 13:53, xxxxxxxx wrote:
I'm afraid I don't know.
I've never heard of anyone doing that. But that doesn't mean it's not possible.As much as I loved VS2010 (it's clean & runs fast on my older computers). I've found that VS2013 works even better. Especially for x64 stuff. And it's much more supported by 3rd party library makers than VS2010.
If you can do it. Put VS2010 out to pasture and stick with 2013 + SP5.
It will make your life a lot easier.VS2015 with SP3 is also pretty good. I plan on probably dumping VS2013 once it also reaches SP5.
-ScottA