对于原因,我试图使用GCC中的顶级组装来定义一些静态函数。 但是,由于GCC没有“看到”这些函数的主体,它警告我它们“被使用但从未定义过。一个简单的源代码示例可能如下所示:
/* I'm going to patch the jump offset manually. */ asm(".pushsection .slen,\"awx\",@progbits;" ".type test1, @function;" "test1: jmp 0;" ".popsection;"); /* Give GCC a C prototype: */ static void test(void); int main(int argc, char **argv) { /* ... */ test(); /* ... */ }接着,
$ gcc -c -o test.o test.c test.c:74:13: warning: ‘test’ used but never defined [enabled by default] static void test(void); ^怎么避免这个?
For Reasons, I'm trying to use top-level assembly in GCC to define some static functions. However, since GCC doesn't "see" the body of those functions, it warns me that they are "used but never defined. A simple source code example could look like this:
/* I'm going to patch the jump offset manually. */ asm(".pushsection .slen,\"awx\",@progbits;" ".type test1, @function;" "test1: jmp 0;" ".popsection;"); /* Give GCC a C prototype: */ static void test(void); int main(int argc, char **argv) { /* ... */ test(); /* ... */ }And then,
$ gcc -c -o test.o test.c test.c:74:13: warning: ‘test’ used but never defined [enabled by default] static void test(void); ^How to avoid this?
最满意答案
gcc在这里很聪明,因为你已经将这个功能标记为静态,这意味着它在这个翻译单元中被定义。
我要做的第一件事是摆脱static说明符。 这将允许(但不要求)你在不同的翻译单元中定义它,所以gcc时不会抱怨。
这可能会带来其他问题,我们必须看到。
gcc is being smart here because you've marked the function as static, meaning that it's expected be defined in this translation unit.
The first thing I'd do is get rid of the static specifier. This will permit (but not require) you to define it in a different translation unit so gcc will not be able to complain at the point of compilation.
That may introduce other problems, we'll have to see.
更多推荐
发布评论