链接可执行文件中的静态库中缺少符号 [英] Missing symbols from static library in linked executable

查看:230
本文介绍了链接可执行文件中的静态库中缺少符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在链接的可执行文件中遗漏的静态库符号的问题。
这里是我的问题的描述:

I have a problem with static library symbols missed in linked executable. Here is the description of my problem:

我有从几个目标文件建立的静态库。这些对象文件提供了多种符号,与之关联:

I have static library built from several object files. These object files provides sevaral groups of symbols, associated with:


  1. 一组C函数和结构体(几个目标文件)。让我们调用相应的符号 level1

  2. 这个C函数和结构体(另一个目标文件)的一组C ++包装类。让我们调用相应的符号 level2

  3. 一组从扩展功能的二级类(另一个目标文件)让我们调用相应的符号 level3

  1. A set of C functions and structs (several object files). Let's call corresponding symbols level1 symbols.
  2. A set of C++ wrapper classes for this C functions and structs (another object file). Let's call corresponding symbols level2 symbols.
  3. A set of C++ wrapper classes inhereted from level 2 classes (another object file) with extended functionality. Let's call corresponding symbols level3 symbols.

Undeground C代码使用几个其他项目和外部库。其中一些是静态的,所以目前这个库也是静态的。

Undeground C code uses several other project and external libs. Some of them are static, so currently this lib is static too.

库与可执行文件链接。此文件直接仅从lib使用 level2 符号。但是在执行过程中,此可执行文件加载的一些动态库需要 level3 符号。

Library is linked with executable file. This file used directly only level2 symbols from lib. But some dynamic libraries loaded by this executable during execution needs level3 symbols.

问题是,由于某种原因被遗漏到这个可执行文件中(nm已批准)。

The problem is, that level3 symbols for some reason are missed into this executable(nm approved).

库本身包含所有符号组。 ALso还有另一个可执行文件与这个库链接,它还包含所有的符号组。这些可执行文件的主要区别是第二个可执行文件(其中显示所有符号)直接使用 符号。

Library itself contains all groups of symbols. ALso there is another executable linked with this library and it also contains all groups of symbols. The main difference between these executables is that second executable (where all symbols are presented) uses leve3 symbols directly.

CMake在调试配置(这意味着g选项呈现在g ++命令)。底层操作系统是GNU / Linux x86_64。 g ++版本是4.4。

The whole project is built with CMake in debug configuration (this means "-g" option is presented in g++ commands). The underlying OS is GNU/Linux x86_64. g++ version is 4.4.

我已经在StackOverflow上检查过几个类似的问题,但我没有找到任何可接受的解决方案。

I've checked several similiar questions on StackOverflow but I haven't found any acceptable solution.

已经尝试过几个链接选项来解决问题(--export-dynamic,--whole_archive),但是这两个选项都没有帮助。

I've already tried several linking options to solve the problem (--export-dynamic, --whole_archive) but neither helps.

我很高兴看到任何想法以解决这个问题,或至少是这种奇怪行为的可能原因。

I'll be glad to see any ideas to solve this problem or, at least, possible reasons of this strange behaviour.

这是用于构建可执行文件的命令行。命令由CMake生成。我只添加--whole_archive选项,然后删除可执行文件和重新运行命令。我也希望你能原谅我用???替换所有项目特定的名称。

This is command line used to build executable. Command was generated by CMake. I only add --whole_archive option, then delete executable and rerun command. I also hope you will excuse me for replacing all project specific names with "???".

exec_name - 我们正在讨论的可执行文件名称

lib_name - 我们正在讨论的库名称

exec_name - name of executable we are talking about
lib_name - name of library we are talking about

/ usr / bin / c ++ - 到g ++ v4.4可执行文件的符号链接

/usr/bin/c++ - symlink to g++ v4.4 executable

/ usr / bin / c ++ -Wextra -g -fPIC CMakeFiles / exec_dir。 dir / main.cpp.o CMakeFiles / exec_dir.dir / options.cpp.o CMakeFiles / exec_dir.dir / runtime.cpp.o CMakeFiles / exec_dir.dir / plugins.cpp.o CMakeFiles / exec_dir.dir / CServer.cpp。 o -o exec_name -rdynamic ../lib/odies?/lib???.a --whole-archive ../../lib/odies?/???lib_name.a ../lib/ / lib ???。so ../../lib/res//lib。?a ../../ ????/lib ??? .a ../../lib/ 0017?/libodies?.a -ldl -lboost_filesystem -lboost_signals -lboost_system -lboost_thread ../../lib/ 0017?/lib]?.so / usr /local/ssl/lib64/libcrypto.so -ldl -luuid -lodbc ../lib/log/libodies?.so ../lib/config/libodies?a -lpthread ../../? ?? / ??? / lib ??? a -Wl,-rpath,/ home / beduin / ??? / build / deb / ??? / lib / ???:/ home / beduin / build / deb / lib / ???:/ usr / local / ssl / lib64

/usr/bin/c++ -Wextra -g -fPIC CMakeFiles/exec_dir.dir/main.cpp.o CMakeFiles/exec_dir.dir/options.cpp.o CMakeFiles/exec_dir.dir/runtime.cpp.o CMakeFiles/exec_dir.dir/plugins.cpp.o CMakeFiles/exec_dir.dir/CServer.cpp.o -o exec_name -rdynamic ../lib/???/lib???.a --whole-archive ../../lib/???/???/lib_name.a ../lib/???/lib???.so ../../lib/???/???/lib???.a ../../???/???/lib???.a ../../lib/???/lib???.a -ldl -lboost_filesystem -lboost_signals -lboost_system -lboost_thread ../../lib/???/lib???.so /usr/local/ssl/lib64/libcrypto.so -ldl -luuid -lodbc ../lib/log/lib???.so ../lib/config/lib???a -lpthread ../../???/???/lib???.a -Wl,-rpath,/home/beduin/???/build/deb/???/lib/???:/home/beduin/???/build/deb/lib/???:/usr/local/ssl/lib64

推荐答案

使用 -rdynamic -Wl,-whole-archive< all your libs> -Wl,-no-whole-archive< boost,pthread等> - 您的一个库不在 - 整个归档

Use -rdynamic -Wl,-whole-archive <all your libs> -Wl,-no-whole-archive <boost, pthread and so on> - one of your libs aren't within --whole-archive

这篇关于链接可执行文件中的静态库中缺少符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆