Hello to the community,
I am developing the implementation of a C++ algorithm as a grasshopper component using the RhinoCommon Visual Studio Extension. I am primarily following XingxinHE instructions on github (I highly recommend it: XingxinHE/CGAL_IN_GRASSHOPPER: Wrapping C++ native code in C# with example of CGAL in Grasshopper.:); in a nutshell it works like this: the RhinoCommon Visual Studio Extension solution contains three projects. The first is a C# project containing the definition of the inputs, outputs and computations of the grasshopper module. The second is a C++ project containing the header and source files to the C++ code. Finally a C# class project organizes the communication between the first two projects.
I have some questions regarding the correct usage of the RhinoCommon Visual Studio Extension, correct usage of Visual Studio, as well as C++ coding in general:
-
Question 1: Regarding best practice in using the RhinoCommon Visual Studio Extension: Say I have defined an algorithm (in the form of header and c++ files, containing functions making up the algorithm) which uses libraries like Geometry-Central, Eigen, etc.. Is this the best outset to use the RhinoVisualStudioExtension or would I do better to somehow structure the project differently?
-
Question 2: Would I do better (Option A) to compile that algorithm and somehow include that build inside the MFC dynamic Link Library project, or (Option B) would I rather just move the header and C++ files to the “Header Files” and “Source Files” folders of the MFC dynamic Link Library and build it all together in the end ?
-
Question 3: To introduce a library being used in the C++ project I have to give the path to the headers (in solution explorer with: C++ project ->properties (Configuration “All Configurations” and Platform “All Platforms”)-> Configuration Properties → C/C++ → General → Additional include directories) and the .lib (in solution explorer with: C++ project ->properties (Configuration “All Configurations” and Platform “All Platforms”)-> Configuration Properties → Linker → General → Additional Library Directories), as well as the .lib name itself (… → Linker → Input → Additional Dependencies). For header-only libraries I only give the path to the headers. Is this the correct and complete approach?
-
Question 4: What is the best ressource for understanding the purpose and functioning of the macros used to declare the C++ code:
// Windows build
#if defined (_WIN32)
#if defined (SFCNATIVE_DLL_EXPORTS)
#define SFCNATIVE_CPP_CLASS __declspec(dllexport)
#define SFCNATIVE_CPP_FUNCTION __declspec(dllexport)
#define SFCNATIVE_C_FUNCTION extern “C” __declspec(dllexport)
#else
#define SFCNATIVE_CPP_CLASS __declspec(dllimport)
#define SFCNATIVE_CPP_FUNCTION __declspec(dllimport)
#define SFCNATIVE_C_FUNCTION extern “C” declspec(dllimport)
#endif // SFCNATIVE_DLL_EXPORTS
#endif // WIN32
// Apple build
#if defined(APPLE)
#define SFCNATIVE_CPP_CLASS attribute ((visibility (“default”)))
#define SFCNATIVE_CPP_FUNCTION ¨__attribute ((visibility (“default”)))
#define SFCNATIVE_C_FUNCTION extern “C” attribute ((visibility (“default”)))
#endif // __ APPLE
My questions are not only rhino specific but also touch on foundational knowledge in C++ and visual studio and as such might be misplaced here. I would appreciate any pointers towards the answers to those questions.
Thank you for your support!
Kind regards,
Merlin