问题
I am compiling a program in Visual Studio 2015, using the FreeType Library. Before, I had used the same project to compile a static library with my own Font class (and many other things), using the library. All was well, and the class worked great. However, I recently changed the project to a Windows application, by changing Properties
->General
->Configuration Type
to Application (.exe)
. That way, I could make a program and edit the code at the same time, without copying all of the 20-some files.
After writing my simple program (which is irrelevant to the question), and tried to recompile, I got many errors I didn't get before. They are as follows:
LNK2001 unresolved external symbol __imp__strncpy [...]\freetype.lib(ftbase.obj)
LNK2001 unresolved external symbol __imp__fread [...]\freetype.lib(ftsystem.obj)
LNK2001 unresolved external symbol __imp__realloc [...]\freetype.lib(ftsystem.obj)
LNK2001 unresolved external symbol __imp__strstr [...]\freetype.lib(truetype.obj)
LNK2001 unresolved external symbol __except_handler4_common [...]\MSVCRT.lib(_chandler4gs_.obj)
There seems to be very little on the net about any of these at all, not to mention for this particular case. All was well when I compiled as a static library. I had switched to compiling an .exe
before, and it worked fine then too. I have dealt with unresolved externals in the past, but this just seems inexplicable.
I am linking with
#pragma comment(lib, "freetype.lib")
. freetype.lib
exists and is in the proper directory.
I am including with:
#include <ft2build.h>
#include FT_FREETYPE_H
If it matters, my program is in C++, and I am linking with other libraries as well. Any help is appreciated.
回答1:
I found a solution: according to this MSDN page, some unresolved externals can be solved by adding msvcrt.lib
and msvcmrt.lib
to the additional dependencies. I tried it, and somehow, it worked. I'm still confused as to how this would solve the issue. And, frankly, I'm still not quite sure was the issue actually was. If anyone could help me understand this, it would be greatly appreciated.
Note:
Similar issues could be caused by a mistmatch in the linkage configuration flags. Question Resolving LNK4098: defaultlib 'MSVCRT' conflicts with provides a good explanation on the issue details and the solution.
回答2:
Thought I'd chime in with my solution - the Runtime Library setting was mismatched (I was linking against a lib built with /MT instead of /MD. That setting is in the C/C++->Code Generation section.)_
回答3:
I had the same problem .I fixed that by adding mvcrt.lib
and msvcmrt.lib
in additional dependencies and adding /NODEFAULTLIB:LIBCMT
to additional option in linker option.
来源:https://stackoverflow.com/questions/40230731/unresolved-externals-when-compiling-with-freetype