Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

c++ - What is the Microsoft Visual Studio equivalent to GCC ld option --whole-archive

When linking a static library against an executable, unreferenced symbols are normally discarded. In my case some otherwise unused objects are used to register their respective classes into a factory and if the objects are discarded, this registration fails.

Under Unix where we use gcc, I can pass the flag --whole-archive to the linker ld (see excerpt from ld documentation below), which makes ld not discard any objects. Is there anything like this for Visual C++?

--whole-archive

    For each archive mentioned on the command line after the
    `--whole-archive' option, include every object file in the archive
    in the link, rather than searching the archive for the required
    object files. This is normally used to turn an archive file into
    a shared library, forcing every object to be included in the
    resulting shared library. This option may be used more than once.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The version of Visual C++ in Visual Studio 2015 Update 2 includes a new flag to link.exe called /WHOLEARCHIVE, which has equivalent functionality to the --whole-archive option to ld. According to the flag documentation:

The /WHOLEARCHIVE option forces the linker to include every object file from either a specified static library, or if no library is specified, from all static libraries specified to the LINK command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...