本文介绍了在一个CMake项目中包含glib.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Ubuntu中使用CMake编译库,其中一个文件包含glib.h。安装软件包,并且 glib.h /usr/include/glib-2.0/glib.h 中。 / p>

我添加了以下内容但编译器仍然找不到glib.h。

  FIND_PACKAGE(glib-2.0)
IF(glib-2.0_FOUND)
INCLUDE_DIRECTORIES($ {glib-2.0_INCLUDE_DIR})
ENDIF()



任何人都知道我想要找什么包裹?



我结束的实际代码使用是

  find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB_PKG glib-2.0)

if(GLIB_PKG_FOUND)
message(Found glib-2.0)
include_directories($ {GLIB_PKG_INCLUDE_DIRS})


解决方案

我建议您浏览以下链接:。



作为参考,您可以查看此用于查找glib2。



这里是:

  find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0)

我建议您在< project root> / cmake / 目录中复制此模块。然后,在您的根CMakeLists.txt文件中使用 find_package


Trying to compile a library in Ubuntu with CMake and one of the file includes glib.h. The package is installed and glib.h is in /usr/include/glib-2.0/glib.h.

I added the following but compiler still cannot find glib.h.

FIND_PACKAGE(glib-2.0)
IF (glib-2.0_FOUND)
    INCLUDE_DIRECTORIES(${glib-2.0_INCLUDE_DIR})
ENDIF()

Anyone know what package I are suppose to look for?

Actual code that I ended up using is

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB_PKG glib-2.0)

if (GLIB_PKG_FOUND)
    message(Found glib-2.0)
include_directories(${GLIB_PKG_INCLUDE_DIRS})
解决方案

I suggest you go through the link: How package finding works.

As a reference, you can have a look at this CMake Module for finding glib2.

The line of your interest here is:

find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0)

I suggest you copy this module in your <project root>/cmake/ directory. And, then use a find_package in your root CMakeLists.txt file.

这篇关于在一个CMake项目中包含glib.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 20:16