我通过选择Debug多线程/单线程配置将VS2017源代码中的Freetype 2.9构建为一个静态库。看起来,静态库被放置在自由类型-2.9\objs\x64\Debug Static\freetype.lib中。
在VS2017中,我在其他库目录中添加了免费类型-2.9\objs\x64\Debug静态。在附加依赖项中,我添加了freetype.lib。并将运行时库设置为MTd。但是,编译会引发链接器错误:
1>------ Build started: Project: HelloFreetype, Configuration: Debug x64 ------
1>Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol __imp_FT_Init_FreeType referenced in function main
1>Source.obj : error LNK2019: unresolved external symbol __imp_FT_Done_FreeType referenced in function main
1>C:\Users\joaqo\Documents\HelloFreetype\x64\Debug\HelloFreetype.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "HelloFreetype.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========Freetype在预处理程序中有不寻常的用途,下面也是代码:
#include <ft2build.h>
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
FT_Library library;
int error = FT_Init_FreeType(&library);
if (error) {
printf("FreeType: Initilization error\n");
exit(EXIT_FAILURE);
}
FT_Done_FreeType(library);
exit(EXIT_SUCCESS);
}同样的错误发生在x86平台上,发布配置和/或将Windows重定向到8.1 (Freetype也是用SDK8.1构建的)。在Freetype 2.7.1中也尝试过,但没有成功。并且试图链接到动态库根本不是问题!
谢谢你的帮助!
发布于 2018-02-27 00:25:05
我按照以下步骤复制了相同的链接器错误,但使用了VS2013。在构建FreeType时,我注意到了几个C4273编译器警告,如下所示:
1>..\..\..\src\base\ftinit.c(321): warning C4273: 'FT_Init_FreeType' : inconsistent dll linkage
1> C:\libraries\freetype-2.9\include\freetype/freetype.h(1987) : see previous definition of 'FT_Init_FreeType'为了解决这些编译器警告,我编辑了config/ftconfig.h FreeType头文件。我换了下面一行,
#define FT_EXPORT( x ) __declspec( dllimport ) x到,
#define FT_EXPORT( x ) extern x然后重建FreeType。在这些更改之后,链接器错误不再发生。
发布于 2018-09-15 21:56:06
我认为,FreeType 2.9中出现此问题的原因是由于ftconfig.h中对FT_EXPORT的定义发生了更改。
// From ftconfig.h - FreeType 2.9
#ifndef FT_EXPORT
#ifdef __cplusplus
#define FT_EXPORT( x ) extern "C" x
#else
#define FT_EXPORT( x ) extern x
#endif
#ifdef _MSC_VER
#undef FT_EXPORT
#ifdef _DLL
#define FT_EXPORT( x ) __declspec( dllexport ) x
#else
#define FT_EXPORT( x ) __declspec( dllimport ) x
#endif
#endif
#endif /* !FT_EXPORT */注意_MSC_VER部分将如何撤消前面定义的内容。此_MSC_VER块在早期版本的FreeType中不存在。
如果您只想构建一个静态库(没有DLL),那么删除_MSC_VER部分如下:
#ifndef FT_EXPORT
#ifdef __cplusplus
#define FT_EXPORT( x ) extern "C" x
#else
#define FT_EXPORT( x ) extern x
#endif
#endif /* !FT_EXPORT */https://stackoverflow.com/questions/48489838
复制相似问题