gcc __attribute __((selectany))是否可以替代Linux? [英] gcc __attribute__((selectany)) alternative for linux?

查看:84
本文介绍了gcc __attribute __((selectany))是否可以替代Linux?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Linux中是否有 __ attribute __((selectany))的替代方法?

i would like to know if there is an alternative for __attribute__((selectany)) in linux ?

我想定义这样的东西:

char * a[] = { "qwe", "zxc" };

放在头文件中,并将其包含在许多将链接在一起的.c文件中.因此,链接器将看到一个以上的"a"定义,因此将不会链接.我读过这个属性(selectany),它只使用a"的第一个定义,不幸的是它只适用于ms windows.所以问题是:linux中还有其他方法吗?

in a header file and include it in many .c files which would be linked together. so the linker will see more than one definition of "a" and therefor will not link. i've read of this attribute (selectany), which will use only the first seen definition of "a", unfortunately it is only for ms windows. so the question is: is there an alternative method in linux ?

编辑:实际问题是:是否有一种方法可以指示链接程序仅使用第一个看到的定义,而忽略其他任何可能的定义(即使它们不同)?我知道有很多定义数据的方法,我不是在寻找如何定义数据的解决方案,相反,我想知道是否有一种方法可以使多个定义并使链接器与第一个看到的对象一起工作...

edit: the actual question is: is there a way to instruct the linker to use only the first seen definition and ignore any other perhaps even if they are different ? i know there are many ways to define my data, i'm not searching for solution of how to define my data, instead i would like to know if there is a way to have multiple definitions and make the linker work with the first seen...

推荐答案

我认为您正在寻找弱" gcc属性.

I think you are looking for the 'weak' gcc attribute.

这篇关于gcc __attribute __((selectany))是否可以替代Linux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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