CMake:通过target_link_libraries链接第三方库

2023-05-16

sdbusplus:通过new_method_call同步调用service的method_风静如云的博客-CSDN博客

例子中需要在编译时链接:-lsdbusplus -lsystemd,这两个第三方库,那么通过cmake怎么指定呢?

其实很简单,跟连接当前工程自己的静态库与动态库一样,使用target_link_libraries即可:

//main.cpp
#include <sdbusplus/bus.hpp>
#include <iostream>
 
int main()
{
    using namespace sdbusplus;
 
    auto b = bus::new_default_system();
    auto m = b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1",
                          "org.freedesktop.login1.Manager", "ListUsers");
    auto reply = b.call(m);
 
    std::vector<std::tuple<uint32_t, std::string, message::object_path>> users;
    reply.read(users);
 
    for (auto& user : 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CMake:通过target_link_libraries链接第三方库 的相关文章

随机推荐