1

I have a project structured as follows:

               exe
                |
               dll
                |
     _______________________
    |           |           |
lib1.lib  lib2.lib  ...  libn.lib

Problem: I need to make the .dll export some symbols that are required by .exe from the .libs linked into this .dll. __declspec(dllexport) has no effect on static libs. How to do this?

Ideally, I also want to select which class need to be exported from those .libs, as opposed to exporting everything.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • Static libraries are linked within the module (DLL, EXE). A static library is not a "child" of a module. – Marius Bancila May 13 '14 at 10:51
  • @MariusBancila: Yes. I need a static library to be linked to a .dll, and that .dll must export some classes from the .libs. – Violet Giraffe May 13 '14 at 10:52
  • I'm not sure it'll work but did you try writing a DEF file? – rodrigo May 13 '14 at 10:52
  • @rodrigo: I'm researching it right now. Obviously, I can't write it by hand due to large amount of code (also, the process of building after adding, say, a new exported class must be automated). – Violet Giraffe May 13 '14 at 10:53
  • How many of these symbols have to be exported? – David K May 13 '14 at 10:54
  • Well, you could try running `dumpbin` or `objdump` parsing the output and building the DEF automatically. Not the prettiest solution but it could work. – rodrigo May 13 '14 at 10:55
  • @DavidK: on the order of tens of classes, each with large number of methods (I want to export classes, not individual methods). – Violet Giraffe May 13 '14 at 10:56
  • @rodrigo: yes, thanks, I figure that. I wonder if there's any way to avoid it. – Violet Giraffe May 13 '14 at 10:57
  • 2
    Using __declspec(dllexport) works fine to get a class in a .lib exported from a DLL. The common problem is that you don't give the linker enough reasons to include the code from the .lib, you'd have to use the /INCLUDE option. Very ugly because of the mangled names and not better than a def file. Or write some dummy code in one of the source files of the DLL project that explicitly references the class members so the linker will bring it in. Very ugly too, it doesn't have to be executable code however. – Hans Passant May 13 '14 at 11:33
  • @HansPassant: Thanks a lot Hans, now I recall having the same problem with linker optimizations on Linux. That tip helped me solve my problem. – Violet Giraffe May 13 '14 at 14:27

0 Answers0