How to compile matlab coder package on different operating system

4 次查看(过去 30 天)
Hi, I'm working on exporting a simulation from MATLAB into C for use on a linux cluster. Unfortunately, the cluster doesn't have MATLAB installed and I won't be able to install it. However, I have been able to convert the program into a standalone C application that runs on my Mac OSX 10.8. I can package the generated .c and .h files, but the generated makefile appears to be specific to the Mac that it was generated on.
My question is: how can I generate a makefile that will then compile the program for use on a linux machine. The makefile functionname_rtw.mk is much more complicated than any makefile I've created and refers directly to the MATLAB_ROOT, MATLAB_BIN, MATLAB_ARCH_BIN and ARCH folders. How can I make the whole package portable.
Thank you.

采纳的回答

Jorik
Jorik 2014-10-15
编辑:Jorik 2014-10-15
I think you can use the packNGo function from Simulink Coder to help relocate all necessary files for an external development environment:
web(fullfile(docroot, 'rtw/ug/program-builds.html#bqufw6y'))
The documentation also contains tips for modifying template makefiles for other platforms:
web(fullfile(docroot, 'rtw/ug/cross-compiling-code-generated-on-a-microsoft-windows-system.html'))
  2 个评论
will
will 2014-10-15
Thanks, that second link was very close to what I was looking for. Just for anyone else who might need help with this. I ended up gutting that big ole makefile down just to the bare bones that I needed for my program to run.
It turned out I didn't need to have any reference to the MATLAB distribution at all and everything was self contained within the packaged code generated by MATLAB Coder. I can't guarantee that this will be the case for everyone, but just in case you can use this minimal makefile.
You just need to modify OBJS to reference all the files that Coder put into the package, and change PRODUCT = yourprogram to be your destination program's actual name and location.
###########################################################################
## Makefile generated for MATLAB file/project
##
## Makefile : thismakefile.mk
## Generated on : Tue Oct 14 17:24:54 2014
## MATLAB Coder version: 2.7 (R2014b)
##
## Build Info:
##
## Final product: $(RELATIVE_PATH_TO_ANCHOR)/yourprogram
## Product type : executable
##
###########################################################################
###########################################################################
## MACROS
###########################################################################
  1. Macro Descriptions:
  2. PRODUCT_NAME Name of the system to build
  3. MAKEFILE Name of this makefile
  4. COMPUTER Computer type. See the MATLAB "computer" command.
PRODUCT_NAME = your program
MAKEFILE = thismakefile.mk
START_DIR = .
RELATIVE_PATH_TO_ANCHOR = ..
#------------------------
  1. BUILD TOOL COMMANDS
#------------------------
  1. C Compiler: CC = gcc
  2. Linker: LD = gcc
#----------------------------------------
  1. code optimization in gcc Build Configuration
#----------------------------------------
CFLAGS = -c -O3
###########################################################################
## OUTPUT INFO
###########################################################################
PRODUCT = $(RELATIVE_PATH_TO_ANCHOR)/yourprogram
PRODUCT_TYPE = "executable"
BUILD_TYPE = "Executable"
###########################################################################
## INCLUDE PATHS
###########################################################################
INCLUDES = -I$(START_DIR)
###########################################################################
## OBJECTS
###########################################################################
OBJS = yourfunction.o rt_nonfinite.o rtGetNaN.o rtGetInf.o main.o
###########################################################################
## SYSTEM LIBRARIES
###########################################################################
SYSTEM_LIBS = -lm
#---------------
  1. C Compiler
#---------------
CFLAGS += $(INCLUDES)
all : $(PRODUCT)
###########################################################################
## FINAL TARGET
###########################################################################
#-------------------------------------------
  1. Create a standalone executable
#-------------------------------------------
$(PRODUCT) : $(OBJS)
###########################################################################
## INTERMEDIATE TARGETS
###########################################################################
#---------------------
  1. SOURCE-TO-OBJECT
#---------------------
%.o : %.c
%.o : $(START_DIR)/%.c
###########################################################################
## MISCELLANEOUS TARGETS
###########################################################################
info :
clean :
James Ryan
James Ryan 2016-9-7
The question specifies Matlab (which I have, including Matlab coder), but the answer depends on Simulink coder (which I don't have). Should these instructions work for me?

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by