MY GOAL IS: to compile a static library (normally .a extension) and have internal symbols hidden (function and variable names) when I open the library file with a text editor.
Currently I am on XC32 compiler of Microchip Technology, who makes the well known PIC microcontrollers.
Actually I can't share here my lib, but I have created a very simple one to make tests. C source code is only:
int variable;
int sum (int a, int b)
{
return a+b;
}
and header is only:
int sum (int a, int b);
Created a library project on mplabX IDE and selected XC32 compiler. The project properties show these options:
- xc32-as -> Have symbols in production build. uncheked
- xc32-gcc -> Have symbols in production build. uncheked
- xc32-ld -> Symbols & Macros -> Symbols. Selected option "strip all symbol info"
Then compiled. Library (.a extension) was generated. I opened it with text editor and the see theat the symbols are yet being shown:
For each of the compiler sections (xc32-as, xc32-gcc, xc32-ld etc), There is a field "Additional options".
I tried to input these options, but no one worked to hide the symbols:
- -fvisibility=hidden on gcc and ld
- -fvisibility=hidden on gcc and strip -r -S -x on ld
If I try strip -r -S -x on gcc I get:
pic32m-gcc.exe: error: strip: No such file or directory
pic32m-gcc.exe: error: missing argument to '-x'
Then I removed the addicional options for ld and gcc, placed "static" in front of the variable and function, and C source become:
static int variable;
static int sum (int a, int b)
{
return a+b;
}
Doing this (adding static in front of all), the symbols get correctly hidden. But on the other hand I am not able to use the lib attached to my app project, because when the compiler shows "undefined reference" to the functions of the lib. This is because: [From Wikipedia] In the C programming language, static is used with global variables and functions to set their scope to the containing file.
Then, how can I reach my goal in this case? (first phrase of the topic). Regards.
EDIT: This is being shown on the project properties on the IDE, I am compiling with it.
All the internal symbols are being shown near the bottom of the lib file where it shows the name of the c file, only in this place shows to c filename