Timeline for Minimal effort method for integrating C++ functions into Mathematica
Current License: CC BY-SA 4.0
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 27, 2020 at 14:55 | history | edited | Arnoud Buzing | CC BY-SA 4.0 | added 143 characters in body |
| Jun 14, 2017 at 17:01 | vote | accept | Szabolcs | ||
| Jun 14, 2017 at 15:36 | history | edited | Szabolcs | CC BY-SA 3.0 | link to excellent tutorial |
| May 23, 2017 at 12:35 | history | edited | CommunityBot | replaced http://stackoverflow.com/ with https://stackoverflow.com/ | |
| Jul 3, 2016 at 14:50 | history | edited | xyz | CC BY-SA 3.0 | added 121 characters in body |
| Jan 12, 2016 at 1:46 | comment | added | matheorem | @Szabolcs Hi, Szabolcs, I didn't make a post because I figure out the solution. String is also working for C++. But we have to set gcc to treat .c file as c++, this can be done by compile option -x c++. In this way, we don't need "Libraries" -> "-lstdc++" or even "Language" -> "C++". We createlibrary using this CreateLibrary[libnewsource, "func", "CompileOptions" -> "-x c++"] | |
| Jan 11, 2016 at 16:55 | comment | added | matheorem | @Szabolcs I was afraid maybe my question is too trivial... Ok, I will ask one. | |
| Jan 11, 2016 at 16:49 | comment | added | Szabolcs | @matheorem I don't know why it doesn't work. You should ask a separate question on describe what you are doing exactly. MinGW-64 is not officially supported but there are questions here on how to get it working. | |
| Jan 11, 2016 at 16:45 | comment | added | matheorem | @Szabolcs Oh, I tried, now it becomes "Compile error: C:\Users\qq\Documents\test.cpp:2:29: fatal error: \ WolframLibrary.h: No such file or directory >>" | |
| Jan 11, 2016 at 16:39 | comment | added | matheorem | @Szabolcs why string fails? This will be so inconvenient. I am using windows mingw. You mean on linux string is OK? | |
| Jan 11, 2016 at 16:36 | comment | added | Szabolcs | @matheorem On some platforms compiling C++ fails unless you write the code in a separate source file. Writing it in a string won't work, it'll always compile as C. Other than that, it's exactly the same as using C, you just need to use the cpp extension for your files. | |
| Jan 11, 2016 at 16:25 | comment | added | matheorem | @Szabolcs Hi, Szabolcs. I tried your option of C++, but failed. For example, I include <complex>, and mma tells me "fatal error: complex: No such file or directory". Arnoud Buzing's answer is very nice and clear, but it is purely on C, not C++, would you please edit his answer and add an complete simple example on C++? | |
| Oct 9, 2015 at 18:47 | comment | added | Arnoud Buzing | Wow, that's bizarre. I've deleted those links until I figure out a better place for it. | |
| Oct 9, 2015 at 18:47 | history | edited | Arnoud Buzing | CC BY-SA 3.0 | deleted 141 characters in body |
| Oct 8, 2015 at 18:21 | comment | added | hYPotenuser | "The full code is here" link is dead in October 2015 -- redirects to a very sketchy location. | |
| Jul 18, 2012 at 11:42 | history | migrated | from stackoverflow.com (revisions) | ||
| Nov 27, 2011 at 13:39 | comment | added | Szabolcs | Another important point when using C++ with the MinGW compiler: it's necessary to pass "Libraries" -> "-lstdc++" to CreateLibrary[], otherwise there will be linking errors for any non-trivial C++ program. Is this a compiler driver bug by any chance? I would have expected this to happen automatically when using "Language" -> "C++" (since the "Libraries" option will be different for different compilers -- so the Mathematica side of my code is now not completely portable) | |
| Nov 27, 2011 at 12:16 | comment | added | Szabolcs | It looks like I'll go with this approach after all! But there's a little problem in the code: after macro expansion, MArgument_setMTensor(Res, m2) will look like (*(Res.tensor)) = m2, i.e. err = MArgument_setMTensor(Res, m2); will eventually "evaluate" to err = m2, which is incorrect and will also prevent the code from being compiled as C++. Could you correct this? Also, if I got it right, one must add EXTERN_C in front of all the DLLEXPORTs if the code is C++. | |
| Nov 16, 2011 at 21:54 | comment | added | faysou | There are plenty of examples in the documentation, I guess it's easier to learn by examples, I tested a dummy example once in VisualC++ and it worked (don't forget "extern C" sometimes) here are some links: reference.wolfram.com/mathematica/LibraryLink/tutorial/… reference.wolfram.com/mathematica/TetGenLink/tutorial/… reference.wolfram.com/mathematica/LibraryLink/tutorial/… reference.wolfram.com/mathematica/CCodeGenerator/tutorial/… | |
| Nov 16, 2011 at 3:14 | comment | added | rcollyer | For me, the case was made with the function CreateLibrary, +1. | |
| Nov 15, 2011 at 23:16 | history | answered | Arnoud Buzing | CC BY-SA 3.0 |