Wednesday, November 17, 2021

[SOLVED] How to create a new file copying a header file with the expanded macro

Issue

I have a header file with a Macro that declare functions. I need to import my header file to the LabView, but his cant read the Macro, so cant identify my declareted functions.

I want to generate another code file with the expanded Macro during the build.

Has a build configuration to do it on Eclipse?

Exemple:

The Macro:

#define FUNCTION_SIGNATURE(TYPE, RET, FUNCTION) \
    RET TYPE##_##FUNCTION(int port, char* id)   \

header.h

FUNCTION_SIGNATURE(TEST, int, init);

I need a file that contains the expanded Macro is like:

int  TEST_init(int port, char* id);

OBS:

  • My project is a shared library (DLL)

  • I'm using a Eclipse IDE for C/C++ Development

  • The compiler is gcc

Edit It's a DLL that I import into labview, when importing it needs a header to link with the DLL's functions, and here's my problem, it can't expand the macro to read the function declarations, so I'd like of a way to pass the expanded macros to another file, the labview undestand just the expanded macro. This problem is only to the header file.


Solution

To obtain a preprocessed header file, use GCC's option -E. It produces an output after the preprocessing stage, which includes the expansion of all macros.

gcc -E library.h -o library_expanded.h will do the trick. Adjust the filenames to your liking.

To automate this in your build, use an appropriate build command of your IDE, or add the expanded header to your Makefile. I suggest to run this command only if the build of your library succeeded.



Answered By - the busybee