필터 지우기
필터 지우기

Coder linking error with multiple C dependencies

조회 수: 3 (최근 30일)
Andy Zelenak
Andy Zelenak 2019년 10월 11일
답변: Andy Zelenak 2019년 10월 11일
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')

채택된 답변

Andy Zelenak
Andy Zelenak 2019년 10월 11일
I needed to add the library to the codegen command in my build script:
codegen -config cfg ... /usr/local/lib/mylib.so

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 External Language Interfaces에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by