zoukankan      html  css  js  c++  java
  • Makefile 中 -rpath -rpath-link

    -rpath和-rpath-link

    假设有3个文件,在同一目录下,有这样的依赖关系

    test->liba.so->libd.so

    如果编译test的时候这样写

    gcc test.c –la

    warning:libd.so, needed by liba.so not found

    解决办法有3个

    方法1

    gcc test.c –la –ld

    方法2

    gcc test.c –la -Wl,-rpath-link ./

    这样就告诉编译器,当要寻找liba的依赖库时候,请到 ./去找

    方法3

    gcc test.c –la -Wl,-rpath ./

    这样就告诉编译器,当要寻找liba的依赖库时候,请到 ./去找

    方法2和方法3有什么区别呢?

    -rpath和-rpath-link都可以在链接时指定库的路径;但是运行可执行文件时,-rpath-link指定的路径就不再有效(链接器没有将库的路径包含进可执行文件中),而-rpath指定的路径还有效,程序回到指定的路径中去找库(因为链接器已经将库的路径包含在可执行文件中了。)最后,不管使用了-rpath还是-rpath-link,LD_LIBRARY_PATH还是有效的。

  • 相关阅读:
    [LeetCode]Subsets II
    [LeetCode]Subsets
    [LeetCode]Combinations
    [LeetCode]Minimum Window Substring
    [LeetCode]Search a 2D Matrix
    [LeetCode]Edit Distance
    [LeetCode]Simplify Path
    Adaboost算法
    [LeetCode]Text Justification
    31、剑指offer--从1到n整数中1出现次数
  • 原文地址:https://www.cnblogs.com/Malphite/p/10405465.html
Copyright © 2011-2022 走看看