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

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 个评论

Can you write your own C header file that includes only the function prototypes you want to use? If the original C++ header file does not have extern "C", how do you know they are not decorated names in the object file?
APIs have parameters with classes from Eigen library and requires the header files..
Including 'extern C' does not resolve the issue. Also, trying to avoid writing mexFunctions for each of the APIs.
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
#include <Eigen/Core>
#include <Eigen/Geometry>
namespace myspace
{
}
#ifdef __cplusplus
}
#endif
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?
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 个)

类别

帮助中心File Exchange 中查找有关 Deploy to C++ Applications Using mwArray API (C++03) 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by