0
votes

In Visual Studio I can get specific symbols exported from a dll using /INCLUDE (Force Symbol References) Linker option. Is there an equivalent option in GCC?

I'm compiling with -fvisibility=hidden so no symbol is exported by default.

2

2 Answers

1
votes

While symbols visibility might work, it is not quite the answer to the question asked. It is not a linker option, and requires source modifications, which might be undesirable. More or less equivalent is export map, but it is only available for GCC with GNU linker. GCC command-line option would be

 -Wl,--version-script=a.map

with a.map looks like

 {
     global: a;
     local: *;
 }

more info at http://www.akkadia.org/drepper/dsohowto.pdf

1
votes

One way to do it is to use __attribute__:

void foo() __attribute__((visibility("default")));

void foo() {
  /* Implementation */
}

This should override your -fvisibility=hidden parameter for this function only. You can also do this:

class __attribute__((visibility("default"))) my_class {
  public:
    myClass();
    ~myClass();

    // Other declarations...
};

This exports the entire class and all declaration contained therein.