代码之家  ›  专栏  ›  技术社区  ›  kolrie

C++可执行文件分发策略

  •  3
  • kolrie  · 技术社区  · 17 年前

    create self-contained executables that would be deployed under a number of Linux distribution

    我写的代码依赖于几个库(更具体地说 RudeSocket yaml-cpp

    起初,我使用了动态链接,但(显然)当我将可执行文件复制到另一个盒子时:

    $ ./main
    ./main: error while loading shared libraries: libyaml-cpp.so.0.2: cannot open shared object file: No such file or directory
    

    当尝试静态编译它时,我也会收到一个错误(因为我没有我提到的yaml-cpp.a文件):

    $ g++ main.cpp parse.cpp parse.h rudesocket-1.3.0/.libs/librudesocket.a -o main -static -L/usr/local/librudesocket-1.3.0/.libs/librudesocket.a(socket_connect_normal.o): In function `rude::sckt::Socket_Connect_Normal::simpleConnect(int&, char const*, int)':
    /root/webbyget/sockets/rudesocket-1.3.0/src/socket_connect_normal.cpp:250: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    /tmp/cc3cEVK1.o: In function `operator>>(YAML::Node const&, Job&)':
    parse.cpp:(.text+0x1a83): undefined reference to `YAML::Node::size() const'
    /tmp/cc3cEVK1.o: In function `handle_job(rude::Socket, char const*)':
    parse.cpp:(.text+0x1b79): undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
    parse.cpp:(.text+0x1bfd): undefined reference to `YAML::Node::Node()'
    parse.cpp:(.text+0x1c10): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)'
    parse.cpp:(.text+0x1dc6): undefined reference to `YAML::Node::size() const'
    parse.cpp:(.text+0x1dee): undefined reference to `YAML::Node::~Node()'
    parse.cpp:(.text+0x1e18): undefined reference to `YAML::Node::~Node()'
    parse.cpp:(.text+0x1e37): undefined reference to `YAML::Parser::~Parser()'
    parse.cpp:(.text+0x1e61): undefined reference to `YAML::Parser::~Parser()'
    (...)
    

    非常重要的是,安装应该在没有人为干预的情况下以自动化的方式进行。

    提前感谢,

    4 回复  |  直到 9 年前
        1
  •  4
  •   genpfault    17 年前

    this technique 试试看。

        2
  •  0
  •   William Pursell    17 年前

        3
  •  0
  •   Nadir SOUALEM    17 年前

    也许对你来说最好的解决方案是使用 CMake .

    CMake CPack .

        4
  •  0
  •   Stephane Rolland    13 年前

    如果您使用平台包管理器(.rpm或.deb),系统将为您检查共享库的正确版本,并在需要时下载。

    CPack