2

I'm looking for a way to hide symbols in a static library built in Visual Studio. I've been able to do it in clang and gcc but I'm not sure if there's a way to do it in VS.

I am building a static library parentlib that needs to be built on Linux (using gcc), OSX (using clang), and Windows (using visual studio compiler). This library makes use of 3 other libraries: childliba, childlibb, childlibc.

I have an API for parentlib and I want only the symbols pertaining to the API to be exposed in the library. For example, if someone ran nm parentlib they wouldn't see any of the symbols in childlib(abc)

The way I do this when building the library using clang/gcc is:

clang -exported-symbols-list <text_file_with_parentlib_api_symbols> ...
gcc --globalize-symbols=<text_file_with_parentlib_api_symbols> ...

Now any symbols that aren't listed in the text file aren't made global in the resultant library.

Is there a way to set up this type of symbol hiding in Visual Studio? I've looked around and asked multiple colleagues but no one seems to think it's possible.

Hosack
  • 1,597
  • 1
  • 8
  • 10
  • I think this is more a question about Microsoft's PE/COFF format (and the `link` tool) than about C or VS. There's a 73-page (200 KB) long specification `pecoff.docx` [available here](https://www.microsoft.com/en-us/download/details.aspx?id=19509), which looks like a good starting point to find out if it is at all possible to achieve the effect you want. (I was unable to find documentation pertaining the `-exported-symbols-list` and `--globalize-symbols` [here](http://clang.llvm.org/docs/genindex.html) or [here](https://gcc.gnu.org/onlinedocs/gcc/Option-Index.html#Option-Index), btw) – mrtnhfmnn Dec 16 '16 at 00:38

0 Answers0