C++ using swig
-
Hi Everyone,
I've been trying to connect to a C++ library from SU(windows) using swig.
No success so far... Not even the most basic examples.
I'm rather new to C++, but compiling swig using python works ok, ruby ?!? no way...Is there anyone that has used swig on a recent(ruby2.x) sketchup version on windows?
I would love to have some tips on this.Some problems I ran into:
- ruby does not seem to provide MSVS builds anymore, only MingW. It seems to me that the ruby build in SU is also done using MinGW, is that correct?
- swig examples are ancient and point to these old MSVS builds, it also seems that(for swig) MSVS would be preferable over MinGW.(I didn't have much trouble compiling swig/ruby on linux.)
I thought it better to ask a general question to see if anyone has been using swig+sketchUp recently before I start "spewing" out build errors might be that a swig or C++ forum would be a better place for this question...
Thanks!
Jan -
Havent tried swig.
Are you using the provided examples at the Github Project ? They should be relatively new.
https://github.com/SketchUp/ruby-c-extension-examplesIf you follow this "not so old" discussion there some info about C++ extensions.
Not swig releated, but you might change idea and go straight C++.
(Can't see why it woulden't be more straightforward using C++ for connecting to a C++ library.)
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=58825As you can see I'm not expert at the subject. But picking up the example I could just hack away. It worked pretty much straight of the bat. Well almost
Thomthom might provide you some more solid advice about the subject..
-
I'm not familiar with SWIG I'm afraid. Bugra set up the SWIG example - I can ping him if it needs be.
-
Hey Guys, this looks great! Too bad that I didn't notice this project before... It even seems to be Swig based! I'll dive right into it
@jolran said:
Are you using the provided examples at the Github Project ? They should be relatively new.
https://github.com/SketchUp/ruby-c-extension-examplesI have been trying the examples from the swig website but these are really old.
Thanks!
-
Good luck!
-
I'm a C++ programmer from way back however I haven't worked with Visual Studio for many years.
I've just installed Visual Studio 2010 Express and installed the examples.
I've also downloaded the SDK. Where should the SDK go?Additionally I am experiencing a link error when trying to build SUEX_HelloWorld and SUEX_UsingSWIG
I'm guessing that the compiler can't find the SDK.I see that slapi.dll started shipping with SU8 to now.
I'm thinking there should be a slapi.lib file. -
I've got it compiling - how do I get it to actually run.
-
@garry k said:
Additionally I am experiencing a link error when trying to build SUEX_HelloWorld and SUEX_UsingSWIG
I'm guessing that the compiler can't find the SDK.You don't need SWIG to make a Ruby C/C++ Extensions. If you just want to use the C API licensing features you just need the basics of what SUEX_HelloWorld demonstrate and then add the C API headers and libs to the project.
-
Like Thomthom said.
If you look at this topic (same as link above) there is a lot of information for setting up things.
TT guides me through the ordeal in a usual friendly way.
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=58825
Also (to my liking) switching to a newer Visual Studio gave better compability with C++ 11
making it easier to work with vectors for ex. I highly recommend doing that. -
I fixed the link error and have SUEX_HelloWorld working.
I also have WritingToAskpFile working.skp_to_xml and xml_to_skp do not compile. They require afx.h and afxole.h which did not ship with Visual C++ 2010 express.
I haven't tried licensed_ruby_extension nor TextureMapping
Jolran - thanks for the tip about the compiler and I will read your link. I'm going to need to play with the XCode compiler as well. So far I haven't found out what the costs will be.
There is a visual studio 2012 express but I don't see a link from microsoft for visual c++ 2011 express.
-
Don't think there was a C++ 2011. There was 2010 and 2013.
Garry, was the skp_to_xml example set up to AFX? Don't think it would need that. Lemme look that up when I get into the office.
-
The stdafx.h file contains
#include <SDKDDKVer.h>
#include <afx.h>
#include <afxole.h> -
So, I asked how that example was made, and it uses MFC for the option dialogs, meaning you cannot use the Express edition to compile it.
The Visual Studio 2013 Community edition would let you compile if you upgraded the project - but then it would not run inside of SketchUp because of runtime clashes.
http://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx -
I've got an XE4 C++ compiler working with slapi.dll for windows X86 but so far only with WritingToAskpFile source code.
The key bit was to create an XE4 compatible lib file by running implib.exe with the correct calling convention. Implib.exe comes packaged with XE4.
implib.exe -a slapi.lib slapi.dll
The -a is for cdecl calling convention which is MS default
I will try with the X64 and see what it takes for Mac OSX versionsThere are a number of advantages at least for me to use XE4
- The XE4 compiler compiles windows 32 + 64 bit and OSX
- There shouldn't be runtime clashes because XE4 uses different libraries
- I have years of borland c and c++ source code
- Hopefully no need to have xcode compiler
I know this is still very preliminary - but I am excited by the possibilities
-
I also have it compiling win32 code in C++Builder 6 - but I did use the XE4 implib.exe
Instead of using all runtime libraries you can compile a self contained exe - quite a bit larger. Then all you need is borlands memory manager as a runtime.
-
I'm currently building my Visual Studio builds with /MT instead of /MD - to prevent the need to install the crts - since I build with VS2013's dev chain instead of the 2010 which SU currently use.
-
I'm just currently playing around to see how far I can take this. Even though I'm licensed with XE4 I prefer the ease of use of C++Builder 6.
I can successfully import libraries from SU8, SU2013, SU2014 and SU2015
The sample code to write an skp file works with SU2013, SU2014 and SU2015 but not SU8It appears the library is significantly smaller for SU8, therefore there must be a lot missing.
I'm thinking that it might be time to drop SU7 and SU8I can remove lots of libraries from CBuilder by simply unchecking things. I can also build microsoft compatible DLL's if needed (change the calling convention)
I've only been playing around with interfacing with SU for the last 3 days. I should have a handle on it by early next week.
Now for Swig and C++Builder 6
-
For my own extensions that I write now I usually drop support for anything older than SU2014 - due to Ruby 2.0 and other improvements since then.
Advertisement