I have written some c code that I want to integrate with matlab in the following method https://www.mathworks.com/help/matlab/matlab_external/publish-interface-to-shared-c-library-on-linux.html
- The first step: Generate Interface on Linux goes well.
- The second step: Define Missing Constructs is not really necessary, my example is so simple it can do this automatically
- Build Interface is where I get the problem.
Here is my matlab code:
clc;
clibgen.generateLibraryDefinition(fullfile("testing.h"),...
"Libraries", fullfile("testing.so"),...
"PackageName", "integrationTest",...
"ReturnCArrays",false,... % treat output as MATLAB arrays
"Verbose",true)
defineintegrationTest;
summary(defineintegrationTest)
build(defineintegrationTest)
The last line, build(defineintegrationTest) is what throws the error. Here is the full output:
Using g compiler. Generated definition file defineintegrationTest.mlx and data file 'integrationTestData.xml' contain definitions for 1 constructs supported by MATLAB. Build using build(defineintegrationTest).
MATLAB Interface to integrationTest Library
Functions int32 clib.integrationTest.addingNumbers(int32,int32)
Building interface file 'integrationTestInterface.so'. Error using clibgen.internal.buildHelper (line 62) Build failed with error: '/usr/bin/ld: cannot find -lting collect2: error: ld returned 1 exit status '.
Error in clibgen.LibraryDefinition/build (line 1297) clibgen.internal.buildHelper(obj, obj.LibraryInterface, '', directBuild);
Error in myIntegrationTest (line 11) build(defineintegrationTest)
The main part of the error seems to be the cannot find -lting collect2: error: ld returned 1 exit status ' part. I made testing.so using the lines:
g -o testing.o -O3 testing.cpp
g -shared -o testing.so testing.o
My testing examples here are super simple. Here's the cpp file.
#include "testing.h"
int addingNumbers(int a, int b){
return a b;
}
And here's the header file
#ifndef TESTING_ /* Include guard */
#define TESTING_
int addingNumbers(int a, int b);
#endif
I also tried to use g to make a shared library with the -lting flag, and got the same error.
g -shared -o testing.so testing.o -lting
Does anyone know what this library is or where I can install it? I have gotten google results that actually return 0 results while looking for things about -lting or libting or matlab ting.
CodePudding user response:
It turns out that you should make the first three letters of your .so file lib. So I changed testing.so to libtesting.so and reran the same steps and it worked. Thank you for your help Cris Luengo, who answered this question.