Passing symbols to library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Passing symbols to library

1,180 Views
RValls
Contributor III

Hi everyone. I have a little question about libraries and the program wich use it, I tell you:

I have done a project with Project Type (in Options->Coldfire Target) as Library, with a cuple of functions.

Now I create another project (this one as Application) and include the library to it, so I can use the functions in it.

Till here everything goes fine. The problem arrives when I have to compile some code or some other code in the library project depending on a symbol defined in the application project. In example:

 

/*In main.h at the application project:*/

#define USE_DUMP_FUNCTION 1

 

/*In utilities.c at the library project:*/

#if USE_DUMP_FUNCTION==1

void function(){

  //Function empty

}

#else

void function(){

  //Function with code

}

#endif

 

The compiler always act as USE_DUMP_FUNCTION=0, it does not recognize the symbol from the other project. I know I should do #include "main.h" in utilities.c, but since I can't know wich one is the path to main.h (because it depends on the application project wich not always will be the same) I can't include that line.

 

So, how can I define a symbol in the application project and the library recognize it so the compiler compiles the appropiate code?

 

Thanks in advance,

Rubén

Labels (1)
0 Kudos
Reply
1 Reply

510 Views
stanish
NXP Employee
NXP Employee

Hi RValls,

 

since the library file (.a) is already compiled into object code you cannot change it based on preprocessor macro. In order change library based on macro you need  to recompile entire library. Other option is to add the library source file directly into your application project and in the "Link Order" move it prior to the library .a file. Linker will then use source code module rather then function from library.

 

In order to pass a preprocessor macro into a library project you can create separate .h file and include it into all library source modules. Such separate .h file would include all such user defined macros.

 

Or you can pass it via library project settings "ALT+F7" ->"Language Settings" -> "C/C++ Preprocessor" -> "Prefix Text". This option is not portable.

 

Stanish

Message Edited by stanish on 2009-04-24 12:08 PM
0 Kudos
Reply