Including glib.h in a CMake project

会有一股神秘感。 提交于 2019-11-30 04:51:20

问题


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})

回答1:


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.



来源:https://stackoverflow.com/questions/10383830/including-glib-h-in-a-cmake-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!