Borrar filtros
Borrar filtros

Coder linking error with multiple C dependencies

3 visualizaciones (últimos 30 días)
Andy Zelenak
Andy Zelenak el 11 de Oct. de 2019
Respondida: Andy Zelenak el 11 de Oct. de 2019
With Coder, I'm trying to compile a function matlab_code.m. It depends on an external C-file, c_code1.c. c_code1.c must be built with another exernal C-file c_code2.c, which depends on -lmylib. So it looks like this:
matlab_code.m
|
c_code1.c ---- c_code2.c
|
-lmylib
All of the individual C object files seem to be built fine because I see output like this after running my build script:
gcc -c -std=c99 ... -I/usr/local/include -L/usr/local/lib -lmylib ... -o "c_code1.o" "/home/file/path/c_code1.c"
gcc -c -std=c99 ... -I/usr/local/include -L/usr/local/lib -lmylib ... -o "c_code2.o" "/home/file/path/c_code2.c"
### Creating standalone executable /home/file/path/matlab_code ...
g++ ... -o /home/file/path/matlab_code ... c_code1.o ... c_code2.o -lm
c_code2.o: In function `function_from_c_code2':
c_code2.c:(.text+0x9d): undefined reference to `function_from_mylib'
So it looks like c_code2.o isn't linked against mylib. Any hints on how I can fix this?
Testing stuff outside of Matlab, some example code that depends on c_code2.c is compiled like this:
gcc simple_c_example.c c_code2.c -o simple_c_example -I/usr/local/include -L/usr/local/lib -lmylib
^ This gcc call works great, but I need to do something similar in Matlab.
Some stuff I have tried in the build script:
coder.updateBuildInfo('addCompileFlags','-I/usr/local/include -L/usr/local/lib -lmylib');
coder.updateBuildInfo('addIncludePaths', '/usr/local/include');
coder.updateBuildInfo('addLinkObjects','libmylib.so','/usr/local/lib')

Respuesta aceptada

Andy Zelenak
Andy Zelenak el 11 de Oct. de 2019
I needed to add the library to the codegen command in my build script:
codegen -config cfg ... /usr/local/lib/mylib.so

Más respuestas (0)

Categorías

Más información sobre External Language Interfaces en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by