如何在CMake中使用pkg-config(juCi ++) [英] How to use pkg-config in CMake (juCi++)

查看:315
本文介绍了如何在CMake中使用pkg-config(juCi ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很高兴地用C ++进行编程,并用g ++编译了很长时间。不久前,我决定购买一个IDE,然后我来到 juCi ++

I've been happily programming in C++ and compiling with g++ for quite a while. Not long ago, I'd decided to get an IDE, and I came accross juCi++.

这个IDE非常出色,但它使用CMake(或Meson)来构建项目。这不是一个问题,直到我必须使用 pkg-config 包含一个库(如果您想知道的话,包含GTK + 3.0)。使用g ++编译时,这可以很容易地完成,但是,由于我对CMake完全陌生,因此我不知道如何在新的IDE中执行它。

This IDE is absolutely brilliant, but it uses CMake (or Meson) to build projects. This wasn't a problem, until I had to include a library (GTK+ 3.0 if you're wondering) using pkg-config. This could be done quite easily when compiling with g++, but, as I am completely new to CMake, I have no idea how to do it in the new IDE.

可以有人请解释一下吗?

Can somebody please explain?

推荐答案

如果您的IDE处理CMake和Meson,它应该能够检测到您的项目文件。我会说去Meson,这是未来,CMake语法有一些怪异的Meson没有。

If your IDE handles CMake and Meson, it should be able to detect your project files. I'd say go for Meson, it's the future, and CMake syntax has a few quirks that Meson doesn't.

Meson文档

他是一个基本的 meson.build ,它可以在 main.c 中找到您的应用程序代码,并生成一个二进制名为 gtk3-test

He's a basic meson.build that expects to find your application code in main.c and produces a binary named gtk3-test.

project('gtk3-test', 'c')

cc = meson.get_compiler('c')
deps = dependency ('gtk+-3.0')
sources = ['main.c']

executable('gtk3-test', sources, dependencies: deps)



CMake



CMake文档

对于CMake,只要看看我的答案如何使用Windows中的cmake更容易地连接gtk库?(这也适用于Linux)。它适用于GTK + 2,但适应GTK + 3很容易,所以可以使用 CMakeLists.txt

For CMake, just give a look at my answer to How do I link gtk library more easily with cmake in windows? (which also works under Linux). It was for GTK+2, but adapting it to GTK+3 is easy, so here's the CMakeLists.txt to use:

project (gtk3-test)
cmake_minimum_required (VERSION 2.4)

find_package (PkgConfig REQUIRED)
pkg_check_modules (GTK3 REQUIRED gtk+-3.0)

include_directories (${GTK3_INCLUDE_DIRS})
link_directories (${GTK3_LIBRARY_DIRS})
add_executable (gtk3-test main.c)
add_definitions (${GTK3_CFLAGS_OTHER})
target_link_libraries (gtk3-test ${GTK3_LIBRARIES})

这篇关于如何在CMake中使用pkg-config(juCi ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆