propagate define to another sourcefile or set compiler flag in targetlink

238 Views Asked by At

I have the following problem:

As part of our (proprietary) test environment, we use C to map the developed C-Code to simulink/targetlink so we can compile it as a S-Function. The whole thing is compiled with visual-c(++)2010

In the development code there is a function that is only accessible when a certain flag/define is set by using #ifdef (because it is a function that gives the tester internal access to some data, which should not be accessible in production code).

  • I tried raising the flag by -DFLAGNAME in the targetlink options. This doesn't help.
  • I used #define FLAGNAME in my mapping code, this helped so far that the warning about the unknown function disappeared (so the header file accepted the flag), but I still get an error at link-time that he can not resolve the external symbol

I can't figure out how to access the function without modifying the development code. Below I try to give an example:

dev.h

#ifdef FLAGNAME
int* access(void);
#endif

dev.c

#include "dev.h"
#ifdef FLAGNAME
int* access(void){
return &data; //data has filescope
}
#endif

customCode.c (mapping code of targetlink)

#define FLAGNAME
#include "dev.h"
int main()
{
  int* bar = access();
  // do other things
}

I have access to all other functions in dev.c and the specific error is:

customCode.obj : error LNK2019: unresolved external symbol access referenced in function main

edit: I found the batch where the compile options are saved and modified it accordingly, this more or less was a solution for the problem. But the question is still, would it be possible to propagate a define to another sourcefile, because this would make the solution portable.

1

There are 1 best solutions below

0
Kami Kaze On BEST ANSWER

In the folder:

C:\Users*USERNAME*\AppData\Roaming\MathWorks\MATLAB*MATLABVERSION*

is the file mexopts.bat

there is a line which starts with set COMPFLAGS= (line 35 in my case) after which all compilerflags may be defined.

There the needed flags can be raised.

In regard to StoryTellers comment in the question, it is not possible to propagate a define from one compilation unit to another.