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

2 views (last 30 days)
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 Comments
James Tursa
James Tursa on 4 Apr 2020
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 on 5 Apr 2020
Edited: BRSC User on 6 Apr 2020
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?

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!