'error: invalid use of incomplete type' when linking MatLab to C++

13 views (last 30 days)
I have to get some data from a MatLab script and use them in a C++ project using MinGW, CMake and CLion. More precisely, I have to link the MatlabEngine and MatlabDataArray libraries to get the coordinates of some Kinect v2 vertices and draw them in an OpenGL 3D world. I've followed several tutorials like this (this is the second part, where it shows how to include the engine.h file) and this. In my trials I've focused on the second link, so I'm going to speak about that one. Adapting the guide to CMake, I've come up with this CMakeLists.txt file:
cmake_minimum_required(VERSION 3.13)
project(3D_avatar)
set(CMAKE_CXX_STANDARD 14)
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
include_directories("D:/Matlab/extern/include" "D:/Matlab/extern/lib/win64/microsoft/")
add_executable(3D_avatar main.cpp glad.c Shader.h stb_image.h Camera.h utils.h)
target_link_libraries(3D_avatar -lglew32 -lglfw3 -lopengl32 -lglu32 -lgdi32 -lMatlabEngine -lMatlabDataArray)
The code where I use the library is very simple:
#include <MatlabEngine.hpp>
#include <MatlabDataArray.hpp>
int main() {
// other code
std::unique_ptr<matlab::engine::MATLABEngine> eg = matlab::engine::connectMATLAB();
// other code
}
Everything seems to look good, since CMake doesn't give me any error. But, when I compile the code, I get:
In file included from D:/Matlab/extern/include/MatlabEngine.hpp:14,
from C:\Users\fredd\CLionProjects\3D_avatar\main.cpp:23:
D:/Matlab/extern/include/MatlabEngine/engine_future.hpp:23:72: error: invalid use of incomplete type 'class std::future<std::unique_ptr<matlab::engine::MATLABEngine> >'
class FutureResult<std::unique_ptr<MATLABEngine>>: public std::future<std::unique_ptr<MATLABEngine>>{
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from D:/Matlab/extern/include/MatlabExecutionInterface/exception.hpp:10,
from D:/Matlab/extern/include/MatlabExecutionInterface.hpp:10,
from D:/Matlab/extern/include/MatlabEngine.hpp:9,
from C:\Users\fredd\CLionProjects\3D_avatar\main.cpp:23:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\future:125:11: note: declaration of 'class std::future<std::unique_ptr<matlab::engine::MATLABEngine> >'
class future;
^~~~~~
In file included from D:/Matlab/extern/include/MatlabEngine.hpp:14,
from C:\Users\fredd\CLionProjects\3D_avatar\main.cpp:23:
D:/Matlab/extern/include/MatlabEngine/engine_future.hpp:138:56: error: field 'future' has incomplete type 'std::future<std::unique_ptr<matlab::engine::MATLABEngine> >'
std::future<std::unique_ptr<MATLABEngine>> future;
^~~~~~
In file included from D:/Matlab/extern/include/MatlabExecutionInterface/exception.hpp:10,
from D:/Matlab/extern/include/MatlabExecutionInterface.hpp:10,
from D:/Matlab/extern/include/MatlabEngine.hpp:9,
from C:\Users\fredd\CLionProjects\3D_avatar\main.cpp:23:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\future:125:11: note: declaration of 'class std::future<std::unique_ptr<matlab::engine::MATLABEngine> >'
class future;
^~~~~~
Plus a bunch of similar errors, but with other functions of the same library. So, since I haven't edited the MatLab library in any way, that makes me wonder if I have linked the library correctly, but I can't really say what's wrong. What can I do?

Answers (1)

FannoFlow
FannoFlow on 16 May 2023
It looks like std::future is an incomplete type,
It looks like MinGW does not fully support C++11 features (future, thread, async, etc) on windows.
You'll likely need to use msbuild for this to compile. I'm not sure if there is a newer MinGW version that does support these features.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!