load C++ shared library into Matlab, files not found
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everybody,
i tried to load a C++ shared library called G+Smo into MATLAB 2016b on Linux. After compiling of G+Smo i got a shared object file "gismo.so" but no header file. After searching i found a header file "gismo.h". In this file you see a lot of "include"-commands:
#include <gsCore/gsForwardDeclarations.h>
#include <gsCore/gsExport.h>
#include <gsCore/gsLinearAlgebra.h>
#include <gsCore/gsFunctionSet.h>
...
I also have all of these other header-files in different folders as you can see above. So I tried to load this library with
loadlibrary('libgismo.so','gismo.h','includepath','/home/chu/Downloads/gismo-stable/src')
But it was not successful and i got the following error massage:
In file included from
/home/chu/Downloads/gismo-stable/src/gismo.h:44:0:
/home/chu/Downloads/gismo-stable/src/gsCore/gsForwardDeclarations.h:17:18:
fatal error: vector: No such file or directory
#include <vector>
^
compilation terminated.
gsForwardDeclarations.h includes the standard vector classes of C++ like
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#include <limits>
But i couldn't find this file in my source folder. How can i put all the standard classes of C++ into MATLAB? Many thanks in advance for your help!
0 comentarios
Respuestas (1)
Guillaume
el 21 de Oct. de 2016
" loadlibrary(libname,hfile) loads functions from shared library, libname, defined in header file, hfile, into MATLAB®. The loadlibrary function only supports calling functions that are callable from C and header files that can be parsed by a C compiler. Functions written in C++ must be declared as extern "C".
A C++ header file cannot be parsed by a C compiler.
Now you may or may not be able to solve this depending on the library. If the exported functions have C signature (they are declared as extern "C"), then the C++ headers are not necessary for talking to the library so you could create a custom header file with just the functions signatures.
If the exported functions actually have C++ signature (e.g. they use std::vector as input or output) then there is no way you can use this library with loadlibrary. Note that this is not a limitation of matlab but of C++.
5 comentarios
Guillaume
el 25 de Oct. de 2016
Strange that you went with the old free but feature limited express version when the more feature complete Community version of the latest Visual Studio is also free.
Visual Studio is just a compiler / editor (a very good one), it cannot transfer data to anything, only compile code that you write. You're still stuck with having to write a wrapper of sort, be it making a dll or a mex file. Now that you're on Windows, you also have the option of making that wrapper a .Net assembly which you'd write in your favorite .Net language (VB, C#, C++, F# even). A .Net wrapper may be the easiest as it's closer to C++ but it'll still require some work.
Ver también
Categorías
Más información sobre C Shared Library Integration en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!