为bazel引入第三方库OSQP

1.下载OSQP库源码

osqp/docs/examples/setup-and-solve.rst at master · osqp/osqp

2.编译OSQP库源码生成OSQP的动态链接库libosqp.so

root@in-dev-docker:/home/yihang/git/osqp# mkdir build
root@in-dev-docker:/home/yihang/git/osqp# ls
CHANGELOG.md  CITATION.cff  CMakeLists.txt  LICENSE  NOTICE  README.md  algebra  build  configure  docs  examples  include  site  src  tests
root@in-dev-docker:/home/yihang/git/osqp# cd build

root@in-dev-docker:/home/yihang/git/osqp/build# cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Debug mode: 
-- We are on a Linux system
-- Embedded mode: OFF
-- Algebra backend: builtin
-- Solver profiling: ON
-- Solver interrupt: ON
-- Using double precision floating-point
-- Using long integers
-- Code generation: ON
-- Derivative support: ON
-- Fetching/configuring QDLDL solver
--   Using double precision floats
--   Long integers (64bit) are ON
--   Static library build is OFF
--   Shared library build is OFF
--   Demo executable build is OFF
--   Not building demo executable
--   Unit testing suite build is OFF
-- Build static library: ON
-- Build shared library: ON
-- Build demo executable: ON
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yihang/git/osqp/build

在build文件夹内,使用cmake .. 调用上级目录的CMakelists.txt,在本目录生成makefile文件

root@in-dev-docker:/home/yihang/git/osqp/build# make

输入make指令,按照makefile编译OSQP库。生成osqp的动态链接库libosqp.so,位置在生成的out文件夹下

3.将OSQP源码当中的头文件,和编译生成的libosqp.so库放入自己工程中

源码中的include文件夹粘贴到自己的工程内部,同理out中的libosqp.so

4.编写BUILD文件

       

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_import", "cc_binary")
package(default_visibility = ["//visibility:public"])

cc_library(
    name = "path_qp_lib",
    srcs = ["path_qp.cc"],
    hdrs = ["path_qp.h"],
    deps = [
        ":osqp_lib",
        "//path_planning/path_convex_space:path_convex_space_lib",
    ],
)


cc_import(
    name = "osqp_lib",
    hdrs = glob(["include/**/*.h"]),
    shared_library = "libosqp.so",
)

cc_binary(
    name = "osqp_demo",
    srcs = ["osqp_demo.c"],
    deps = [
        ":osqp_lib"
    ],
)

告诉编译工具自己去哪里调用osqp的方法和头文件。

其中使用bazel的cc_import(),告诉编译器去哪找动态链接库libosqp.so以及osqp库的头文件。

并在path_qp_lib中的deps中添加":osqp_lib"(cc_import()进来的库文件),即使用bazel的cc_library的deps,告诉编译器去哪找osqp_lib,从而在path_qp.cc中使用osqp库的头文件以及libosqp.so

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/betterthanYSD/article/details/134076450

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值