gpt4 book ai didi

c++ - 如何在 Visual Studio 中静态链接 FreeType2?

转载 作者:太空宇宙 更新时间:2023-11-04 01:48:31 26 4
gpt4 key购买 nike

我通过选择Debug Multithreaded/SingleThreaded 配置从 VS2017 中的源代码将 Freetype 2.9 构建到静态库中。貌似静态库放在了freetype-2.9\objs\x64\Debug Static\freetype.lib

在 VS2017 中,在 Additional Library Directories 中,我添加了 freetype-2.9\objs\x64\Debug Static。在 Additional Dependencies 中,我添加了 freetype.lib。并将Runtime Library 设置为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 SDK 重新定位到 8.1(Freetype 也是使用 SDK 8.1 构建的)。也尝试使用 Freetype 2.7.1 但没有成功。并且尝试链接到动态库是完全没有问题的!

感谢您的帮助!

最佳答案

我按照这些步骤重现了相同的链接器错误,但使用的是 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。进行这些更改后,链接器错误将不再发生。

关于c++ - 如何在 Visual Studio 中静态链接 FreeType2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48489838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com