필터 지우기
필터 지우기

Accessing C API (no class from C++ library) from Command line or script

조회 수: 8 (최근 30일)
BRSC User
BRSC User 2020년 4월 4일
편집: BRSC User 2020년 4월 6일
I have a C++ built library in ubuntu which exposes C APIs. Associated header-file defines the APIs without use of 'extern C'. The header file also includes other headerfiles from other packages (Eigen).
  • seems cannot use loadlibrary. I tried library-name headerfile-name,i get:
> loadlibrary libfile.so file.h
Failed to preprocess the input file.
Output from preprocessor is:file.h:5:9: warning: #pragma once in main file
#pragma once
^~~~
file.h:7:10: fatal error: Eigen/Core: No such file or directory
#include <Eigen/Core>
^~~~~~~~~~~~
compilation terminated.
  • do i need to use other mechanism? (fairly new to matlab)
  댓글 수: 4
James Tursa
James Tursa 2020년 4월 4일
You haven't answered my question. If the original C++ header files did not have extern "C" in them, why do you think they are not decorated names in the object library file?
BRSC User
BRSC User 2020년 4월 5일
편집: BRSC User 2020년 4월 6일
Compiler errors when I add include path (-I equivalent) for the additional header locations with mex command:
In file included from /usr/include/c++/8/cmath:42,
from /local/eigen-git-mirror/Eigen/src/Core/util/Macros.h:586,
from /local/eigen-git-mirror/Eigen/Core:19,
from /local/src/base5/mex/mx-wrapper.c:3:
/usr/include/c++/8/bits/cpp_type_traits.h:67:8: error: expected identifier or ‘(’ before string constant
extern "C++" {
^~~~
.
.
/usr/include/c++/8/bits/memoryfwd.h:50:1: error: unknown type name ‘namespace’
namespace std _GLIBCXX_VISIBILITY(default)
^~~~~~~~~
This may be issue from MEX only supported with 6.3.0. I have installed g++ 8.3.0.
Eigen headers are not protected from name mangling, if you are refering to these as "original C++ headers". Does it mean that these data structures (e.g. Vector3d, Affine3d etc from Eigen/Core) need to be converted into pointers and use primitive / matlab data (e.g. matlab::data::Array, matlab::data::Struct etc) in the MX file?
As per mathworks, If you have a C++ shared library that exports functionality that can be called from another application, then you can use these classes and functions directly in MATLAB, passing data back and forth between MATLAB and C++.
Document is a bit unclear (to me). Hence the questions. Does this require:
  • is mexFunction() from C Matrix API prefered interface for C like APIs? This is an older interface and suggested for C or C & C++ combination.
  • OR to use C++ MEX API (and implement operator() ) to access C like APIs soures? Not sure if this is meant only for C++ objects (with operator() accessor)?
  • is it possible / recommended to use loadLibrary framework to load prebuilt shlib with C++14?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C++ Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by