0

I have a set of C files that are compiled and linked into a library. If I create a normal dynamic library (.so, .dylib or .dll) I can make sure only those functions marked as EXPORTED are visible to users of the library. EXPORTED is defined as __attribute__((visibility("default"))) on clang/gcc, and __declspec(dllexport) on Windows. This is all trivial stuff.

Now, I want to create a static library instead, and I want to get the same result, namely that only functions marked EXPORTED are visible to users.

For clang and gcc I do this by running:
ld -r file1.o file2.o ... -o combined.o

and then
objcopy --localize-hidden combined.o

(On macOS the last step is not necessary, since the Xcode ld will localize hidden symbols when doing the partial linking step.)

After that, it is trivial to create a .a library out of the single combined.o file using ar.

Now to the question: Is it possible to achieve something with similar effect on Windows?

I have tried reading up on Visual Studio tooling, but found nothing. I have also tried using llvm-ld on Windows to combine several .obj files into a single combined.obj, but it had trouble parsing several of my original .obj files, and the combined file could not be linked against using Visual Studio tools, which is a hard requirement. (In short, it felt very immature.)

0