我在Windows 7中用MinGW编译,使用Code :: Blocks作为IDE。一切都应该是最新的。我注意到有一些类似的问题,但这些似乎是关于链接动态库,而不是编译静态库。无法使用MinGW链接FreeType 2库; ld.exe:找不到-lfreetype
我想使用FTGL能够在OpenGL中使用文本。 FTGL要求安装FreeType 2。我下载了FreeType源代码,然后使用mingw32-make.exe按照INSTALL.GNU指令从CMD.EXE构建静态库。
按照说明指示,我从FreeType安装的基本目录中运行mingw32-make。是如预期的控制台输出:
D:\freetype-2.4.4>mingw32-make
FreeType build system -- automatic system detection
The following settings are used:
platform win32
compiler gcc
configuration directory .\builds\win32
configuration rules .\builds\win32\w32-gcc.mk
If this does not correspond to your system or settings please remove the file
'config.mk' from this directory then read the INSTALL file for help.
Otherwise, simply type 'make' again to build the library.
or 'make refdoc' to build the API reference (the latter needs python).
Could Not Find D:\freetype-2.4.4\objs\ftmodule.h
Generating modules list in ./objs/ftmodule.h...
"* module: truetype (Windows/Mac font files with extension *.ttf or *.ttc)"
"* module: type1 (Postscript font files with extension *.pfa or *.pfb)"
"* module: cff (OpenType fonts with extension *.otf)"
"* module: cid (Postscript CID-keyed fonts, no known extension)"
"* module: pfr (PFR/TrueDoc font files with extension *.pfr)"
"* module: type42 (Type 42 font files with no known extension)"
"* module: winfnt (Windows bitmap fonts with extension *.fnt or *.fon)"
"* module: pcf (pcf bitmap fonts)"
"* module: bdf (bdf bitmap fonts)"
"* module: sfnt (helper module for TrueType & OpenType formats)"
"* module: autofit (automatic hinting module)"
"* module: pshinter (Postscript hinter module)"
"* module: raster (monochrome bitmap renderer)"
"* module: smooth (anti-aliased bitmap renderer)"
"* module: smooth (anti-aliased bitmap renderer for LCDs)"
"* module: smooth (anti-aliased bitmap renderer for vertical LCDs)"
"* module: psaux (Postscript Type 1 & Type 2 helper module)"
"* module: psnames (Postscript & Unicode Glyph name handling)"
done.
眼见为平台和编译器两者都正确,我再次运行make命令:
D:\freetype-2.4.4>mingw32-make
(bunch of calls, building objects then linking them, until:)
ar: creating objs/freetype.a
这产生在目录d文件freetype.a: \的FreeType-2.4.4 \ OBJ文件。
然后,我在Code :: Blocks中将步骤链接到该项目,添加了一些代码来测试FTGL,并尝试构建它。
我有两个错误,这取决于我如何尝试做事。
如果我向链接器(-LD:\ freetype-2.4.4 \ objs)提供了正确的目录,并且链接到-lfreetype,那么一切都很好,直到ld.exe退出时出现标题错误,无法找到-lfreetype。
如果我没有提供正确的目录,我会得到相同的错误。找不到图书馆。
如果我将freetype.a文件的名称更改为libfreetype.a,并提供正确的目录,我会得到几个未定义的引用。
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x250): undefined reference to `FTPixmapFont::FTPixmapFont(char const*)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x258): undefined reference to `FTFont::Error() const'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x274): undefined reference to `FTFont::FaceSize(unsigned int, unsigned int)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x308): undefined reference to `FTFont::Render(char const*, int, FTPoint, FTPoint, int)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x316): undefined reference to `FTPixmapFont::~FTPixmapFont()'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x328): undefined reference to `FTPixmapFont::~FTPixmapFont()'
collect2: ld returned 1 exit status
如果我提供错误的目录,我再次遇到以前的错误,它找不到库。
我发现奇怪的是,当遵循安装文件中的指示时,make会产生一个名称不是以lib开头的库。我检查了每一个其他.a文件开始与lib-。而且好像链接器正在寻找文件libfreetype.a。那么为什么创建freetype.a代替?这是使用我用来编译程序的库使用相同的编译器。
无论如何,不知道从哪里去。我想过使用属于MinGW软件包的MSys shell,但我没有太多经验,INSTALL.UNIX中的指令假定你知道更明显的命令。他们提到使用./configure [options],而没有提到哪些选项可能是明智的。可能对具有更多系统知识的人很明显,但MSys是我第一次使用sh。
我很感谢这件事的任何帮助。