0

I am trying to generate C code for a Matlab function. It uses mongoose web server for communication. If I place the .h/.c files in the same folder as the .m file I can compile everything fine using:

coder.cinclude('mongoose.h');
coder.updateBuildInfo('addSourceFiles','mongoose.c');
coder.cinclude('rest.h');
coder.updateBuildInfo('addSourceFiles','rest.c');

I would like to keep my .c files and .m files separate, so moving C files to a folder named native/ causes compilation to fail as expected. Thus, I tell Matlab where to find them using:

customDir = '/full/path/to/native';
coder.updateBuildInfo('addIncludePaths', customDir);
coder.updateBuildInfo('addSourcePaths', customDir);

Which works. However it works only with absolute paths and not with relative paths. This is a problem since each contributor to this projects keeps the source folder in a different location. What is the proper way to tell Matlab native file locations using relative paths to Matlab working directory?

2 Answers 2

0

If you just want to generate C code (and not compile), I'd suggesting adding the relative locations to those files to the Matlab Path. You can do this with:

addpath('the_relative_path_to_native')

Or even better:

addpath(fullfile(cd(), 'the_relative_path_to_native'))

After issuing this command, Matlab searches this folder for .m function as well as included C files. This should solve your problem as described.

But later, if you want to compile the generated code, the included folders will not be copied/merged/included in the codegen directory created by Matlab, so you should handle that in a different manner, such as including the directory in your custom makefile os adding a command to copy the required files to a folder convenient for compilation.

Sign up to request clarification or add additional context in comments.

Comments

0

You can also use the $(START_DIR) marcro which gives you the path to the working folder of your project.

Just just neet to specify where your source files are relative to this path then

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.