First, some minimal code:
// file "t1.h":
int get1();
// file "t1.c":
int get1(){return 1;}
// file "t2.h":
int get2();
// file "t2.c":
int get1(){return 99;} // <- duplicate definition of get1(), I would like to hide it somehow
int get2(){return 2;}
// file "t3.c":
#include <stdio.h>
#include "t1.h"
#include "t2.h"
int main(int argc, char ** argv) {
printf("%d\n", get1());
printf("%d\n", get2());
}
Compilation command
gcc -c t1.c && gcc -c t2.c && gcc -c t3.c && gcc t1.o t2.o t3.o -o t3`
Result is error:
t2.c:(.text+0x0): multiple definition of 'get1'.
Problem is clear, get1()
is defined twice.
Why I still search for solution?
- I do not need the 2nd definition of
get1()
, I would like to discard it hide it. - Deleting it from the file, marking it
static
or renaming it, does not work for me, because "t1.c" and "t2.c" are generated automatically.
Question:
Is there a way to somehow hide selected symbols without modifying .c
file?
Or alternatively to show only chosen symbols.
Or rename them.
Something like: gcc -c t2.c --hide-symbol=get1
More details why I want this:
There is program flex
which generates lexer .c
file.
There is possibility to change some behavior by re-defining macros.
I need two distinct lexers to be generated, both used by same program.
Edit: actual solution
In flex
it is possible to change prefix from "yy*" to "somethingelse*" as mentioned in comments.
http://westes.github.io/flex/manual/Code_002dLevel-And-API-Options.html#index-prefix