필터 지우기
필터 지우기

load C++ shared library into Matlab, files not found

조회 수: 14 (최근 30일)
skyforcen73
skyforcen73 2016년 10월 21일
댓글: Eduardo Cruz Urioso 2020년 6월 18일
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!

답변 (1개)

Guillaume
Guillaume 2016년 10월 21일
" 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
Guillaume
Guillaume 2016년 10월 25일
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.
Eduardo Cruz Urioso
Eduardo Cruz Urioso 2020년 6월 18일
Hi, how can I add an wrapper for c++ headers?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by