cmake Freetype2未在Windows上正确链接

jjjwad0x  于 2022-12-04  发布在  Windows
关注(0)|答案(1)|浏览(300)

我已经和freetype2战斗了一个星期,试图让它在Windows 32位上工作,但它就是不工作。我的CMakeLists.txt如下:

cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_CXX_STANDARD 17)

project(template-project) # change the name here

file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})

list(APPEND CMAKE_PREFIX_PATH "D:/Installs/ProgFiles/glew")

find_package( OpenGL REQUIRED )

include_directories( ${OPENGL_INCLUDE_DIRS} )

# this is so stupid
set(CMAKE_SIZEOF_VOID_P 4)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
  # ensure 32 bit on clang
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target i386-pc-windows-msvc")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target i386-pc-windows-msvc")
  add_definitions("--target=i386-pc-windows-msvc")
endif()

set(FT_DISABLE_HARFBUZZ TRUE)

target_include_directories(${PROJECT_NAME} PRIVATE
  libraries/minhook/include
  libraries/gd.h/include
  libraries/gd.h/
  libraries/imgui
  libraries/glad/include
  libraries/stb
  libraries/freetype2/include
)

add_subdirectory(libraries/minhook)
add_subdirectory(libraries/cocos-headers)
add_subdirectory(libraries/glfw)
add_subdirectory(libraries/glm)
add_subdirectory(libraries/freetype2)

target_link_libraries( ${PROJECT_NAME} ${OPENGL_LIBRARIES} glfw )
if( MSVC )
    if(${CMAKE_VERSION} VERSION_LESS "3.6.0") 
        message( "\n\t[ WARNING ]\n\n\tCMake version lower than 3.6.\n\n\t - Please update CMake and rerun; OR\n\t - Manually set 'GLFW-CMake-starter' as StartUp Project in Visual Studio.\n" )
    else()
        set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT GLFW-CMake-starter )
    endif()
endif()

target_link_libraries(${PROJECT_NAME} opengl32.lib minhook cocos2d rpcrt4.lib glm ${PROJECT_SOURCE_DIR}/libraries/freetype2/objs/Win32/Release/freetype.lib)

输出中最大的问题是以下几行:

[cmake] -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
[cmake] -- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) 
[cmake] -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR) 
[cmake] -- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) 
[cmake] -- Could NOT find BZip2 (missing: BZIP2_LIBRARIES BZIP2_INCLUDE_DIR) 
[cmake] -- Could NOT find BrotliDec (missing: BROTLIDEC_INCLUDE_DIRS BROTLIDEC_LIBRARIES)

我用的是windows,完全不知道如何修复这些问题。我试过通过mingw32安装zlib,我也试过用类似minhook的方法链接它,很高兴没有用。

pzfprimi

pzfprimi1#

我建议在使用MinGW时使用一种与手动下载开源依赖项不同的方法。与其搜索单独的二进制下载,不如切换到使用msys 2来安装MinGW,并使用msys 2的包管理来管理所有依赖的开源库。
第一步是删除当前的MinGW安装,这样PATH中就没有冲突/可能不兼容的MinGW dll,这可能会在将来执行程序时导致问题。
然后安装msys 2:How to install MinGW-w64 and MSYS2?
然后打开mingw 32终端,默认情况下安装在“C:\msys64\mingw32.exe”中,并使用msys 2 pacman的软件包管理器来安装依赖软件包。
msys 2的网页在此页面的上方中央有一个方便的套件搜寻功能:https://packages.msys2.org/queue
让我们从依赖项中的zlib开始。在搜索框中输入zlib,然后按search。输入mingw-w64-zlib,然后查找mingw的i686软件包,以找到32位mingw的正确软件包。我找到了mingw 32的zlib的以下链接,它有以下页面:https://packages.msys2.org/package/mingw-w64-i686-zlib?repo=mingw32
的安装说明列在页面中央:pacman -S mingw-w64-i686-zlib
因此,将此命令复制到mingw 32终端:

JMDLAPTOP1+dresc@JMDLAPTOP1 MINGW32 ~
# pacman -S mingw-w64-i686-zlib
resolving dependencies...
looking for conflicting packages...

Packages (1) mingw-w64-i686-zlib-1.2.13-2

Total Download Size:   0.10 MiB
Total Installed Size:  0.39 MiB

:: Proceed with installation? [Y/n]

按Y安装此软件包。

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 mingw-w64-i686-zlib-1.2.13...   102.8 KiB   126 KiB/s 00:01 [###############################] 100%
(1/1) checking keys in keyring                               [###############################] 100%
(1/1) checking package integrity                             [###############################] 100%
(1/1) loading package files                                  [###############################] 100%
(1/1) checking for file conflicts                            [###############################] 100%
(1/1) checking available disk space                          [###############################] 100%
:: Processing package changes...
(1/1) installing mingw-w64-i686-zlib                         [###############################] 100%

JMDLAPTOP1+dresc@JMDLAPTOP1 MINGW32 ~

对其他相关程序包继续执行类似的过程。

相关问题