【问题标题】:Building and using shared libraries with bjam使用 bjam 构建和使用共享库
【发布时间】:2010-01-22 08:53:43
【问题描述】:

在 ubuntu 上使用 bjam,我正在构建一个 c++ 共享库并尝试在可执行文件中使用它。我必须构建为共享,因为它不会链接为静态(出现许多未定义的引用)。没关系。

两个相关的问题:

1) 使用 Jamfiles 的层次结构,我的 exe 项目 (testServerHub) 依赖于共享库 (pythonManager)。这是 exe 的 Jamfile:

echo "Compiling serverHub//test" ;

# declare project name
project serverHub//testServerHub
    : build-dir ../_gcc/intermediate 
    ;

# build unit-test using these source files, dependent libraries and settings
exe testServerHub
    : # Source
      ..\\..\\..\\common\\0_8_1\\test\\runner.cpp
      successfulTest.cpp

      # Dependent libraries by path and project name
      ../controller/pythonManager//pythonManager 
      /boost//unit_test_framework

    : # Settings
      <link>shared
    ;

install ..\\bin : testServerHub ; 

这是我的 lib Jamfile:

echo "Compiling serverHub/controller//pythonManager" ;

# declare project name
project serverHub/controller//pythonManager     
    : requirements 
      <define>URTH_SERVERHUB
    : build-dir ../../_gcc/intermediate 
    ;

# build library using these source files and settings
lib pythonManager 
    : ../../../../common/0_8_1/controller/pythonManager/pythonManager.cpp
      ../../../../common/0_8_1/controller/pythonManager/cppInterfaceBase.cpp
      cppInterfaceServerHub.cpp
      /boost/python//boost_python
      /user-config//python
    : <link>shared
    ;

# copy and rename
install ../../lib : pythonManager ; 

如果我运行“bjam pythonManager”,pythonManager 共享库将被构建并复制到我的项目 lib 文件夹(通过最终安装命令)。但是,如果我运行“bjam test”,则 testServerHub 和 pythonManager 都已构建,但 libpythonManager.so 不会复制到项目 lib 文件夹 - 安装命令不会运行!

2) 好的,作为临时解决方法,我先构建 libpythonManager.so,然后构建 testServerHub 可执行文件。编译和链接。在运行时,可执行文件抱怨找不到 libpythonManager.so。这并不奇怪,因为运行时链接器不知道我的项目 lib 文件夹。我如何告诉它在某个目录中查找共享库?或者如果安装命令对依赖库构建没有影响,我该如何将 libpythonManager.so 安装到 /usr/local/lib 中?

非常感谢

【问题讨论】:

  • 一种方法是使用单元测试规则而不是 exe 规则。在这种情况下,共享库在运行时以某种方式链接。不过,这对我的主要可执行文件没有帮助。在 linux 上执行此操作的正确方法是什么?

标签: linux gcc ubuntu bjam boost-build


【解决方案1】:

我认为你可以在 exe Jamfile 中使用&lt;install-dependencies&gt;on,就像在

install ..\\bin : testServerHub : <install-dependencies>on <install-type>LIB ;

这将安装 exe 所依赖的所有库 (LIB)。

参见例如http://www.boost.org/doc/tools/build/doc/html/bbv2/tasks/installing.html 作为参考。

【讨论】:

    猜你喜欢
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    相关资源
    最近更新 更多