Coder linking error with multiple C dependencies

2 ビュー (過去 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 Center および File ExchangeExecution Speed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by