Coder linking error with multiple C dependencies
2 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 External Language Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!