Hi Michael,
From my understanding, you want to integrate new C++ code generated from your latest MATLAB functions into an existing project without redefinition errors, particularly from utility files like “rtwtypes.h”.
There are a few strategies you can employ:
1. Namespace Isolation for Types: Since the redefinition errors arise from common utility headers like “rtwtypes.h”, you can manually wrap the inclusion of these headers in namespaces. While MATLAB Coder doesn't directly support namespacing utility headers, you can create a wrapper header file for the new code that places these “includes” within a namespace.
For example, create a new header file “new_code_wrapper.h” :
namespace NewCode
{
#include "new_generated_code.h"
}
2. Conditional Compilation: Use preprocessor directives to manage the inclusion of generated utility headers. This can help avoid redefinitions by ensuring that each header is only included once.
#ifndef NEW_RTW_TYPES_H
#define NEW_RTW_TYPES_H
#include "rtwtypes.h"
#endif
3. Separate Compilation Units: Compile your old and new MATLAB-generated code in separate units. This allows each compilation unit to manage its definitions independently by reducing conflicts.
4. Custom Build Scripts: If you're using a build system like “Cmake” or “Make”, consider writing custom build scripts that handle the inclusion of headers and compilation of different modules, ensuring that conflicts are avoided.
Hope this helps!