- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在正确链接 C 语言库时遇到了一些问题。
我确定这是我不完全理解的神秘 C 链接规则之一,但我想不出来。
我有 libn,我将其编译成静态库 libn.a
nm libn 显示:
doug@ninja:~/projects/libnw/build$ nm ../../libn/build/libn.a |grep nIndex
00000034 T nIndex
00000000 D nIndex_
00000026 T nIndex_finalize
00000013 T nIndex_init
00000000 T nIndex_map
我还有libnw,依赖libn。 libnw 上的 nm 显示:
doug@ninja:~/projects/libnw/build$ nm libnw.a |grep Index
U nIndex
但是,当我编译针对 libnw 和 libn 的编程链接时,我得到:
doug@ninja:~/projects/libnw/build$ make
[ 70%] Built target nw
[ 80%] Built target test-template
Scanning dependencies of target test-Core
[ 85%] Building C object tests/nw/mvc/Core/CMakeFiles/test-Core.dir/Tests.c.o
[ 90%] Building C object tests/nw/mvc/Core/CMakeFiles/test-Core.dir/test.c.o
Linking C executable test-Core
../../../../libnw.a(Impl.c.o): In function `nwCore__Impl_init':
/home/doug/projects/libnw/src/nw/mvc/Core/Impl.c:76: undefined reference to `nIndex'
collect2: ld returned 1 exit status
make[2]: *** [tests/nw/mvc/Core/test-Core] Error 1
make[1]: *** [tests/nw/mvc/Core/CMakeFiles/test-Core.dir/all] Error 2
make: *** [all] Error 2
原因很明确。当 Tests.c --> Tests.c.o 时,它没有选择 nIndex 作为它需要保留的符号:
doug@ninja:~/projects/libnw/build$ nm tests/nw/mvc/Core/CMakeFiles/test-Core.dir/Tests.c.o
U MyController
000005a4 T Tests
00000000 D Tests_
00000125 T Tests_can_attach_controller
00000080 T Tests_can_create_core
000003d3 T Tests_can_handle_native_event
000001c8 T Tests_can_set_controller
00000322 T Tests_can_update
00000000 t Tests_core_factory
0000056c T Tests_finalize
000005c0 T Tests_getType
0000048c T Tests_init
U nFactory
U nTest
U nType_nalloc
U nType_nfree
U nwCore
U nwDummyContext_getType
U nwDummyEvents_getType
U nwDummyRender_getType
U nwIContext_getType
U nwIEvents_getType
U nwIRender_getType
(注意测试对象文件中完全没有 U nIndex)。
因此,我可以通过在我的测试脚本中添加对 nIndex() 的调用来轻松解决此问题,但这并没有解决基本问题:
程序依赖于 liba 依赖于 libb,liba 缺少需要解析的 libb 中的符号,但程序没有对这些符号的引用,因此它们似乎被剥离了。
我做错了什么?
(是的,我正在使用 cmake 构建并依赖于 libn 和 libnw 的静态构建版本)。
编辑:
现在有了链接器行:
/usr/bin/gcc -std=c99 -g CMakeFiles/test-Core.dir/Tests.c.o \
CMakeFiles/test-Core.dir/test.c.o \
CMakeFiles/test-Core.dir/helpers/MyController.c.o \
CMakeFiles/test-Core.dir/helpers/MyModel.c.o \
-o test-Core -rdynamic \
/home/doug/projects/tapspin-android/source/deps/libn/build/libn.a \
../../../../libnw.a
最佳答案
我没有看到您的链接行,所以我很难确定,但这似乎是一个订购问题
如果libb
需要的所有符号都在liba
中,那么你应该先列出libb
,这样它们就被列出了作为要解析的符号,当访问 libb
时,它们将被解析。这本身并不是剥离,它只是不包括(即它是遗漏而不是主动去除,我是不是在吹毛求疵?也许吧)
此外,有时如果存在循环依赖(liba
需要来自 libb
的一些符号,而 libb
需要来自 liba 的一些符号
) 必须多次列出库(这不是 cmake
的答案,因为我不使用 cmake
,但多年来一直使用链接器,这是一个常见错误)。
请注意,与库中的符号不同,目标文件中的所有符号都是链接的
首先尝试的最简单的解决方法是交换两个库的顺序
关于c - 如何在 C 中正确链接以阻止符号被剥离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7624194/
有没有一种快速的方法(无需显式循环遍历字符串中的每个字符)并剥离或保留它。在 Visual FoxPro 中,有一个函数 CHRTRAN() 可以很好地完成这项工作。它是 1:1 字符替换,但如果替换
在 python/pandas 中清理多类型数据框的值,我想修剪字符串。我目前正在按照两个说明进行操作: import pandas as pd df = pd.DataFrame([[' a '
通常情况下,我正在编写剥离新类型的唯一构造函数的函数,例如在以下函数中返回不是 Nothing 的第一个参数: process (Pick xs) = (\(First x) -> x) . mcon
我正在尝试逐渐将 AOSP 从其默认应用程序中剔除。但是我想知道我要应用的方法是否是正确 并且是最有效 . 在查看了这样做的方法后,我来到了以下 方法: (示例应用程序 - “package_name
使用时 hg log --template "{date|isodate} --- {rev}:{node|short} --- ... " 2011-10-07 19:25 -0400 --- 1:
我想在 mySQL 中创建数据库位置记录。我在选择框中有以下 html 字符串: Aka AkaArarimuAwhituBombayBuckland '> 我不想在数据库中手动输入记录,而是想去掉
我目前正在开发一个 Android 项目,其中我使用 Android NDK 用 C 语言进行一些计算。 只要我不运行 proguard,我的应用程序就可以正常工作,但是当我运行时,“reportPr
我想要一个通用的 .js 文件,对于页面上遇到的每个 form,在提交时,它会从所有 textarea、 中删除 HTML input 和 select 元素。我觉得我缺少一个基本技巧。 $("for
我正在尝试编写一个简单的 Python 脚本,它将文本文件作为输入,删除每个非文字字符,并将输出写入另一个文件中。通常我会采取两种方式: 使用正则表达式结合 re.sub 将每个非字母字符替换为空字符
我敢肯定这个问题以前有人问过,但我已经看过了,但找不到答案,或者我只是做错了什么。 HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.Htm
我有这行代码: var newmsg = $('' + ""+dateFormat(timesp)+ " | " + pseudo + ' : '); newmsg.find(".msg").text
我正在尝试从 Windows 路径中删除前缀。我尝试使用 strip_prefix 来做到这一点方法,但它失败了。您可以在 Rust Playground 上试用.即使在 RUST_BACKTRACE
使用这个 question ,我正在试验 substr 和 strrpos,但似乎无法正确处理。 我有一个来自 MySQL 数据库的名称列,其中包含名字和姓氏,如下所示: Doe, Jane A 现有
好的,我如何使用正则表达式删除 http AND/OR www 只是为了让 http://www.domain.com/ 进入 domain.com 假设 x 是任何类型的 TLD 或 cTLD 输入
我正在尝试从 this website 中抓取项目. 项目是:品牌、型号和价格。由于页面结构的复杂性,spider 使用了 2 个 xpath 选择器。 品牌和型号商品来自同一个 xpath,价格来自
这个问题在这里已经有了答案: 关闭 11 年前。
我有一个包含一些 html 标签的字符串,如下所示: " This is a test " 我想去掉标签之间的所有多余空格。我尝试了以下方法: In [1]: import re In [
我目前有一个 URL 列表 http://www.website.com/dynamic/download.ashx?id=123/12/12345 http://www.website.com/dy
我环顾四周,找不到一种简单/单行的方法来去除 numpy 数组中的空格:: print(type(p)) print(p) [{' SPL', 'GPU', 'bcc'} {'ANZ ', 'ROI
我有一个自定义共享点应用程序,其安全模型取决于 HTTP header 。当从移动设备发出请求时,每个请求都会添加一个名为 HTTP_RIM_DEVICE_EMAIL 的 http header 。我
我是一名优秀的程序员,十分优秀!