2

I want to distribute a static library which consists of many source files and therefore, when compiled, consists of many object files. Within the object files there are some static functions and some functions which are not static. The non-static functions are needed because functions in one object file may need to be called from other objects.

I have one of the objects which is basically the API into the library and it has an associated header file which the application developer would include in their project in order to use the library. I want the symbols in that header file to be the only ones exposed to the application using the library.

I use IAR to compile my code into .a file, then include the public API header into my application and link the .a to my application.

The problem is that the non-static functions in my library which are supposed to only be called by other objects in the library are visible to the application using the library. This is an issue if the application tries to define a function with the same name as one of my library's functions (by accident, coincidence or intentionally). I cannot make every function static (and therefore visible to only their compilation unit) because then that function would be unusable to the rest of the library.

Basically I want to hide symbols from the application who is using the library.

I have a way to fix this in Keil already which works: In Keil, I can do partial linking by actually linking my library using the flags -ldpartial --privacy --no_locals --no_comment_section and by providing a steering file through the option --edit=steering.txt

to selectively choose what symbols I show and hide. Example of a steering file:

HIDE *
SHOW my_public_func1
SHOW my public_func2

Is there any way to do this in IAR. I.e. is there a way to partially link a library and then link that library into an application.

What I have tried: https://www.iar.com/support/tech-notes/linker/hiding-symbols-from-a-library-using-isymexport-with-a-steering-file/

This is a good idea, but it requires loading my library separately onto the device when what I want to do is link it right into the application. Ideally, I would want to link the generated .out file from the above iar.com link into the application instead of loading it separately.

TomE
  • 345
  • 2
  • 13

0 Answers0