- Provide the path to the Linux version of the library, e.g. <libtest.a> when they are calling gcc. For example, if <libtest.a> is located in "C:/MyFolder/", the gcc command should have the flag -L/C:/MyFolder/ -ltest, where by -L we tell gcc where the library is located and with -ltest we tell that the name of the library is libtest (basically we should drop the name lib from the name of the library when passing it to gcc).
- Tell gcc to link the code against the math library by including the flag -lm as some of the functions in rt_logging.c are using the math library. This will take care of the error "undefined reference to floor".
How to compile Windows generated codes with a platform-specific library on Linux machine?
    5 views (last 30 days)
  
       Show older comments
    
    MathWorks Support Team
    
 on 8 Feb 2021
  
    
    
    
    
    Edited: MathWorks Support Team
    
 on 3 Mar 2021
            I am using MATLAB R2020a to generated code from my Simulink Model. In order to use an external library in my code,  I am using the
>> coder.updateBuildInfo('addLinkObjects', <libtest.lib>)
command in the MATLAB Function Block to link my Coder object with the target library. By doing so, my model can be compiled successfully on Windows.
As the next step, I want to compile the generated code on my Linux machine. I am following the workflow mentioned in this MATLAB Answer page:
But get an issue related to my specific use-case. The library <libtest.lib> I called in my code is platform-specific, which means it has a different version for Linux environment <libtest.a>. I have to use <libtest.lib> at first in order to successfully generate code on a Windows machine, but how can I let my code point to a different version of that library on Linux?
Accepted Answer
  MathWorks Support Team
    
 on 26 Feb 2021
        
      Edited: MathWorks Support Team
    
 on 3 Mar 2021
  
      This can be achieved by slightly modifying the workflow mentioned in that MATLAB Answer page. When calling the "gcc" in this case. make sure it is linking the model to a library.
So the gcc command should be used like below when compiling the code in Linux (assuming the name of the library is libtest):
gcc -L/C:/MyFolder/ -ltest ... (the rest of the flags)
Please note that when calling gcc you might have to change the order of the library flags (e.g. put them to the end) based on the dependency of the source codes to the libraries and the interdependency of the libraries themselves.
0 Comments
More Answers (0)
See Also
Categories
				Find more on Simulink Coder in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!