PlatformIO Community

How to select the proper library with a #ifdef directive

Hello

I have to libs with the same primitive names. I want to select one of the two depending upon a #define variable.
It does not work as I expect. Could you help me to find the right way ?
Here is the principle :


//#define USE_FOO

#define USE_BAR

#ifdef USE_FOO

#include "foo.h"

#endif

#ifdef USE_BAR

#include "bar.h"

#endif


void app_main()

{

    hello();

}

Here are the libs
bar.h

#pragma once
void hello();

bar.c :

#include "bar.h"
#include  <stdio.h>
void hello()
{
    printf("\nhello from bar\n");
}

now foo.h (same as bar.h)

#pragma once
void hello();

foo.c ()

#include "foo.h"
#include  <stdio.h>
void hello()
{
    printf("\nhello from foo\n");
}

The problem is whatever I select USE_FOO or USE_BAR
the result is always hello from foo at the execution level

How to select the proper file during the link process?

Thank you for your help.