Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Preventing access to internal library subroutines

OP1
New Contributor III
814 Views

I apologize if this question has already been asked and answered before... I would like to know how to prevent future users of my libraries to call someinternal subroutines in these libraries.

For instance, assume that I have two subroutines S_PUBLIC and S_PRIVATE in a library. S_PUBLIC is meant for usage by customer's codes; S_PRIVATE is a utility subroutine that is used by S_PUBLIC but which should not be accessed outside the library.

How would I enforce this?

Thank you!

Olivier

0 Kudos
1 Solution
Steven_L_Intel1
Employee
814 Views
There is no way to prevent someone from calling a routine in a static library. Typically what one would do is choose a naming convention that separates the private routines from the public ones.

Of course, of you provide your procedures in modules, you can use Fortran's accessibility attributes (PUBLIC/PRIVATE) to specify that everything is private unless made public. This affects users of the module - theoretically, if someone figured out the private routine name and wrote their own interface (without using the module), they could call it.

View solution in original post

0 Kudos
5 Replies
TimP
Honored Contributor III
814 Views


I suppose you would put the private subroutine in a module and declare it private.

0 Kudos
OP1
New Contributor III
814 Views
Quoting - tim18


I suppose you would put the private subroutine in a module and declare it private.


Thanks Tim... yes, this solution would work if you only have a limited number of small subroutines. But this is not convenient when you have a lot of large subroutines... the resulting module would be unwieldy for later maintenance, upgrades etc...

Is there another solution?

For instance, I am sure that the MKL libraries refer to many internal subroutines that one cannot access when these libraries are linked in a program. How is it done?

Olivier

0 Kudos
anthonyrichards
New Contributor III
814 Views
Make it a dynamic link library and only export the public symbols?

0 Kudos
OP1
New Contributor III
814 Views
Quoting - anthonyrichards
Make it a dynamic link library and only export the public symbols?


Yes, but what about static libraries? There is no equivalent facility provided for static libraries?

0 Kudos
Steven_L_Intel1
Employee
815 Views
There is no way to prevent someone from calling a routine in a static library. Typically what one would do is choose a naming convention that separates the private routines from the public ones.

Of course, of you provide your procedures in modules, you can use Fortran's accessibility attributes (PUBLIC/PRIVATE) to specify that everything is private unless made public. This affects users of the module - theoretically, if someone figured out the private routine name and wrote their own interface (without using the module), they could call it.
0 Kudos
Reply