我可以链接未解决的引用中止吗? [英] Can I link unresolved reference to abort?

查看:186
本文介绍了我可以链接未解决的引用中止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个相当大的项目的一小部分写一些小测试。尝试链接这个野兽是不幸的是,如果没有将整个项目连接在一起,我不想做的(这是一个非常复杂的系统,查找所有的依赖项和东西,我不想干预它)。 p>

现在,我知道确实的引用函数在我的测试期间不会被调用的函数,恰好恰好是共享文件的功能的一部分,我做测试。



有没有办法简单地链接这些未解决的引用,我们说,中止或什么?



我使用gcc(g ++),因为我们使用gcc(g ++)用于编译/链接,版本3.4.4。平台是unix(solaris / sparc如果这很重要)。

解决方案

你可以告诉链接器忽略未解决的符号。我找不到将它们链接到 abort 或类似选项的选项。



忽略未解析符号的策略在目标文件中是最自然的,我想:

  gcc -Wl, -  unresolved-symbols = object-files obj.o another.o etc.o 

其他选项包括(引用 man ld ):

  --unresolved-symbols = method 
以处理未解析的符号。方法有四个可能的b $ b ble值:

ignore-all
不报告任何未解决的符号。

report-all
报告所有未解析的符号。这是默认值。

ignore-in-object-files
报告共享
库中包含的未解析符号,但如果它们来自常规对象
文件,则忽略它们。

ignore-in-shared-libs
报告来自常规对象文件
的未解析符号,但如果它们来自共享库,则忽略它们。这可以
在创建动态二进制文件时很有用,并且已知
它应该引用的所有共享库都是链接器命令行中包含的


共享库自己的行为也可以通过 - [no-] allow-shlib-undefined选项来控制。

通常,链接器将为每个
报告的未解析符号生成错误消息,但是选项--warn-unresolved-sym-
bols可以将其更改为警告。

在我的Linux系统上尝试调用未解析的函数导致Segmentation fault。


I'm trying to write some small tests for a fairly small part of a fairly large project. Attempting to link this beast is unfortunately fairly impossible without linking the entire project together, which I don't want to do (it's a pretty complex system for finding all the dependencies and stuff, and I perfer not to meddle with it).

Now, I know for certain that the functions that the referenced functions won't be called during my test, the just happen to be part of functions which share file with stuff that I do test.

Is there any way to simply link these unresolved references to, let's say, abort, or something? Or is there a tool which creates the appropriate stub object file where all calls result in abort, given the set of object files that I have?

I use gcc (g++) for compiling/linking, version 3.4.4. Platform is unix (solaris/sparc if that's important).

解决方案

You can just tell linker to ignore unresolved symbols. I couldn't find option that links them to abort or something like that.

The policy to ignore unresolved symbols in object files only is the most natural, I suppose:

gcc -Wl,--unresolved-symbols=ignore-in-object-files  obj.o another.o etc.o

Other options include (quoting man ld):

   --unresolved-symbols=method
       Determine how to handle unresolved symbols.  There are four possi-
       ble values for method:

       ignore-all
           Do not report any unresolved symbols.

       report-all
           Report all unresolved symbols.  This is the default.

       ignore-in-object-files
           Report  unresolved  symbols  that  are  contained  in   shared
           libraries,  but  ignore  them if they come from regular object
           files.

       ignore-in-shared-libs
           Report unresolved symbols that come from regular object files,
           but  ignore them if they come from shared libraries.  This can
           be useful when creating a dynamic binary and it is known  that
           all  the  shared  libraries  that it should be referencing are
           included on the linker's command line.

       The behaviour for shared libraries on their own can also  be  con-
       trolled by the --[no-]allow-shlib-undefined option.

       Normally  the  linker  will  generate  an  error  message for each
       reported unresolved symbol but the  option  --warn-unresolved-sym-
       bols can change this to a warning.

On my Linux system attempts to call the unresolved function result in "Segmentation fault".

这篇关于我可以链接未解决的引用中止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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