Can I ask VC++ linker to ignore unresolved externals?

纵然是瞬间 提交于 2019-12-23 07:44:38

问题


I'm trying to build a very complex open-source project with VC++. The project consists of dozens of libraries and one executable depending on those libraries.

For some reasons VC++ linker doesn't want to see about 40 functions implemented in one of those libraries and reports "unresolved external reference" on each, so I can't link. I don't want to waste time resolving the problem - those functions are likely never called.

I'd like to just ask the linker to link what it sees and insert some reasonable error handling (like reporting an error and terminating the program) instead of missing functions. How can I do that?


回答1:


You can use the /FORCE:UNRESOLVED linker option.

The documentation for that contains the rather understated warning:

A file created with this option may not run as expected.

In pratice, there'll be no error handling - just a crash.




回答2:


If the functions are truly never called, then create actual libraries (.lib files) for the libraries. Then the linker will only extract from the libraries what's needed.

The linker's job is to resolve all references, so I don't think you're going to get it to insert error handling code.

P.S. The first thing I'd check is to see if C functions got compiled as C++, leading to the missing symbols.




回答3:


If they're never called, remove the references from your project. If they are called, then fix the damn problem. There's no real other option here.




回答4:


There are some notable exceptions, but most OpenSource projects are not designed to be built under VisualStudio.

Generally for a Windows port you are better off using either cygwin or the mingw system. My advice is usually for mingw, unless the program uses a lot of Unix OSey calls like pipes and signals.



来源:https://stackoverflow.com/questions/2326460/can-i-ask-vc-linker-to-ignore-unresolved-externals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!