t.c
#define __CONCAT(x,y) x##y
#ifdef SUFFIX
#define __SUFFIX(x) __CONCAT(x,_)
#else
#define __SUFFIX(x) x
#endif
#ifdef UPPER
#define __c(U,l) __SUFFIX(U)
#else
#define __c(U,l) __SUFFIX(l)
#endif
#define xaxpy __c(XAXPY, xaxpy)
#include <stdio.h>
char* xaxpy;
char* DAXPY;
int main()
{
printf(xaxpy);
printf(DAXPY);
}
e.c
char* xaxpy = "ln";
char* xaxpy_ = "ls";
char* XAXPY = "UN";
char* XAXPY_ = "US";
, link-time --defsym:
Cetin@BAKA-CHAN ~
$ gcc -D UPPER -D SUFFIX -c t.c e.c
Cetin@BAKA-CHAN ~
$ gcc -o t t.o e.o -Wl,--defsym=_DAXPY=_xaxpy
Cetin@BAKA-CHAN ~
$ ./t
USln
Cetin@BAKA-CHAN ~
$
There should also be a way to give the linker different scripts to handle a large number of such symbol definitions. So I could make this part of the build process to automatically create linker scripts that create mappings between different cases.
source
share