mmoran
mmoran

Reputation: 1001

gcc __attribute__ with separation of declaration and definition

I want to take advantage of GCC's visibility attribute.

To such end, in my executable, I have a function I wish to be visible to any plugins, so they can use it to register themselves. I therefore use __attribute__((visibility("default"))) on it and -fvisibility=hidden as an option on the command line.

This article seems to imply that attributes can only be used on declarations.

Is it possible to have the implementation of a function in a separate .cpp file and apply the attribute to only the declaration?

Upvotes: 3

Views: 1121

Answers (1)

Yes. It is often done that way, the __attribute__ appears only at the declaration.

Upvotes: 4

Related Questions