Answered by:
combining static libs

Question
-
I have a project that compiles to a static library. It's too big so I was forced to break it up into two separate projects/libraries. My question: is it possible to link them into one library. I tried putting together a project specifying the two libraries as input, but end up with nothing being output. I gather the linker looks at what is needed from the two projects, determines that there are no dependencies, and does nothing.Wednesday, March 2, 2011 7:19 PM
Answers
-
I had the second library added as an additional dependency and I was also specifying the lib command as a post-build step. Judging from the size of the libraries the final library output by the lib command does indeed combine the libraries. The inclusion of the second library causes the warnings above. Removing that gets rid of the warnings, while running the lib command as a post-build step produces the desired single library from the combination of the original two. I'm good, thank you.
- Marked as answer by Yi Feng Li Thursday, March 10, 2011 3:34 AM
Thursday, March 3, 2011 5:10 PM
All replies
-
The linker only pulls in the code from the libraries if you actually reference the exported entry points. Did you do that?Wednesday, March 2, 2011 7:24 PM
-
"I gather the linker looks at what is needed from the two projects, determines that there are no dependencies, and does nothing."
No. Is there a way to do that other than the usual way, which would be to use the library's code in code?
Wednesday, March 2, 2011 8:13 PM -
Specify the first .lib as an object file input when building the 2nd library.
In the properties page, it would be under Librarian | General, under "Additional Dependencies".
Microsoft Test - http://tester.poleyland.com/Wednesday, March 2, 2011 8:31 PM -
Won't that suffer from the same problem? Since none of the code in the second library calls the code in the first, it won't link it in?Wednesday, March 2, 2011 9:47 PM
-
You can use the lib command line tool to do that:
lib lib1.lib lib2.lib /out:full.lib
- Proposed as answer by Vic Vega Thursday, March 3, 2011 3:57 PM
Wednesday, March 2, 2011 10:10 PM -
Won't that suffer from the same problem? Since none of the code in the second library calls the code in the first, it won't link it in?
I don't know how you set up your experiment, but the way I have done it (and documented for you) works just fine.
Microsoft Test - http://tester.poleyland.com/Wednesday, March 2, 2011 10:20 PM -
When you link it in to an exe or dll are you able to use functions from the first lib that is linked into the second lib?Thursday, March 3, 2011 1:45 PM
-
When I run this command, I am told that:
"This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library"
Thursday, March 3, 2011 2:56 PM -
Hmm, that's a warning, in theory the resulting lib file should be fine. This can happen if the input libraries contain .obj files with the same name. You should be able to tell which files cause this from the warning message.
Thursday, March 3, 2011 3:12 PM -
Upon further review you seem to be right. I have a couple of duplicate files. I think we may have this resolved.Thursday, March 3, 2011 3:16 PM
-
Sorry to say, but it appears that the lib command is going through each obj in the second library and saying:
"This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library"
Thursday, March 3, 2011 3:40 PM -
Hmm, not sure why it would do that. Unless you have functions that are defined in multiple files.Thursday, March 3, 2011 4:15 PM
-
I had the second library added as an additional dependency and I was also specifying the lib command as a post-build step. Judging from the size of the libraries the final library output by the lib command does indeed combine the libraries. The inclusion of the second library causes the warnings above. Removing that gets rid of the warnings, while running the lib command as a post-build step produces the desired single library from the combination of the original two. I'm good, thank you.
- Marked as answer by Yi Feng Li Thursday, March 10, 2011 3:34 AM
Thursday, March 3, 2011 5:10 PM