【问题标题】:how to use my own library c++ ubuntu如何使用我自己的库 c++ ubuntu
【发布时间】:2013-08-17 11:24:33
【问题描述】:

大家好,我在使用测试库时遇到了一些问题,希望有人可以帮助我。

有问题:

这是测试库的层次结构:

dir : ./include/libhello/hello.hxx
dir : ./src/hello.hxx
dir : ./CMakeLists

使用 cmake 我生成了/hello.so

但现在我在将它用于外部程序时遇到问题prog.cc

您能告诉我如何将 prog 与.so 链接并创建可执行文件等,非常感谢您的回复。 :)

【问题讨论】:

    标签: c++ linux ubuntu linker


    【解决方案1】:

    您可以将库复制到 /usr/local/lib,如果您将其添加到项目中,链接器应该会选择它。

    在我的 CMakeLists.txt 中有:

    function(import_library target name)
        find_library(${target}_import_${name} ${name})
        add_library(${${target}_import_${name}} SHARED IMPORTED)
        target_link_libraries(${target} ${name})
    endfunction()
    
    function(project_import_library name)
        import_library(Project ${project})
    endfunction(
    
    project_import_library(dependency)
    

    用你的名字替换项目/项目和依赖项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-24
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      相关资源
      最近更新 更多