Borrar filtros
Borrar filtros

I couldn't compile my c code with the shared library generated by matlab from m files. How can I resolve this?

9 visualizaciones (últimos 30 días)
Compile option
""" gcc -O3 -I/usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/extern/include/ -L/usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/extern/lib/glnxa64/ -L/for_testing -ltest main.c -o main
/tmp/ccip5bsu.o:
In function `main':
main.c:(.text.startup+0xa6): undefined reference to `mxCreateDoubleMatrix_730_proxy'
main.c:(.text.startup+0xba): undefined reference to `mxCreateDoubleMatrix_730_proxy'
main.c:(.text.startup+0xc5): undefined reference to `mxGetPr_proxy'
main.c:(.text.startup+0x125): undefined reference to `mxGetPr_proxy'
main.c:(.text.startup+0x1a9): undefined reference to `mlxMyMult'
main.c:(.text.startup+0x1b3): undefined reference to `mxGetPr_proxy'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1

Respuestas (2)

Philip Caplan
Philip Caplan el 14 de Abr. de 2015
This looks like a linker error where the implementations of "mxCreateDoubleMatrix", "mxGetPr", etc. were not found. Is the command you posted complete? I see the path was specified but the only library linked against was "test". Please try adding "-lmx -lmclmcrrt" at the end of your compiling command.
If that does not help, please provide some more details about your operating system and MATLAB version.
  1 comentario
K R S Nandhan
K R S Nandhan el 23 de Mzo. de 2021
I have similar error but my code is in c++.
g++ -g -o main main.cpp
/usr/bin/ld: /tmp/ccn43UqG.o: in function `rt_atan2d_snf(double, double)':
/home/nandhan/games/test/rcamcoder.cpp:32: undefined reference to `rtNaN'
/usr/bin/ld: /tmp/ccn43UqG.o: in function `rt_powd_snf(double, double)':
/home/nandhan/games/test/rcamcoder.cpp:70: undefined reference to `rtNaN'
/usr/bin/ld: /home/nandhan/games/test/rcamcoder.cpp:81: undefined reference to `rtInf'
/usr/bin/ld: /home/nandhan/games/test/rcamcoder.cpp:88: undefined reference to `rtInf'
/usr/bin/ld: /home/nandhan/games/test/rcamcoder.cpp:103: undefined reference to `rtNaN'
collect2: error: ld returned 1 exit status

Iniciar sesión para comentar.


Hyunwoo Kim
Hyunwoo Kim el 14 de Abr. de 2015
Thank you. Philip!
It worked out.
There are couple of comments. First, Matlab generated test.so for my case. However, I had to rename it "libtest.so" to use "-ltest" option in gcc. Also as you suggested, I added some other library "-lmwcpp11compat", "-lmwmclmcrrt".

Categorías

Más información sobre C Shared Library Integration en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by