我如何强制GCC编译未使用的函数? [英] How can I force GCC to compile functions that are not used?

查看:504
本文介绍了我如何强制GCC编译未使用的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将项目中的一些代码拆分为一个单独的库,以便在另一个应用程序中重用。这个新的库有定义但不是定义的各种功能,而且我的当前项目和其他应用程序都将实现它们自己的这些功能版本。



我在我的原始项目中实现了这些函数,但是它们不会在其中任何位置调用。他们只被这个新的图书馆调用。结果,编译器优化了它们,并且我发现链接失败。当我为这些函数添加一个虚拟调用时,链接失败消失。



有没有办法告诉GCC编译这些函数,即使它们没有被调用?

我在SuSE linux上使用 -O2 编译gcc 4.2.2(x86-64_linux_2.6.5_ImageSLES9SP3- 3)。

解决方案

您可以尝试 __ attribute__((used))在gcc手册中声明函数的属性

>

I am splitting off some of the code in my project into a separate library to be reused in another application. This new library has various functions defined but not implemented, and both my current project and the other application will implement their own versions of these functions.

I implemented these functions in my original project, but they are not called anywhere inside it. They are only called by this new library. As a result, the compiler optimizes them away, and I get linking failures. When I add a dummy call to these functions, the linking failures disappear.

Is there any way to tell GCC to compile these functions even if they're not being called?

I am compiling with gcc 4.2.2 using -O2 on SuSE linux (x86-64_linux_2.6.5_ImageSLES9SP3-3).

解决方案

You could try __attribute__ ((used)) - see Declaring Attributes of Functions in the gcc manual.

这篇关于我如何强制GCC编译未使用的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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