Coder linking error with multiple C dependencies
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Andy Zelenak
am 11 Okt. 2019
Beantwortet: Andy Zelenak
am 11 Okt. 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')
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Execution Speed finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!