1

I'm stumped. Here is the output of ld.

/usr/lib/libvisual-0.6/actor/actor_avs_superscope.so: undefined reference to `visual_mem_free'
/usr/lib/libvisual-0.6/actor/actor_avs_superscope.so: undefined reference to `visual_mem_malloc0'

Here are the macros:

#define visual_mem_new0(struct_type, n_structs)           \
    ((struct_type *) visual_mem_malloc0 (((visual_size_t) sizeof (struct_type)) * ((visual_size_t) (n_structs))))

#define visual_mem_malloc(size)     \
    visual_mem_malloc_impl (size, __FILE__, __LINE__, __PRETTY_FUNCTION__)

#define visual_mem_malloc0(size)    \
    visual_mem_malloc0_impl (size, __FILE__, __LINE__, __PRETTY_FUNCTION__)

#define visual_mem_realloc(ptr, size)   \
    visual_mem_realloc_impl (ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)

#define visual_mem_free(ptr)        \
    visual_mem_free_impl (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Now it doesn't add up. One line's saying that visual_mem_free is missing, which is a macro. The other's saying that visual_mem_malloc0 is missing, but the code's actually calling visual_mem_new0, which suggests it sees visual_mem_new0.

priv = visual_mem_new0 (SuperScopePrivate, 1);

visual_mem_free (priv);

Any clues?

Edit: Bumping.. Maybe some fresh eyes can help?

Edit: By the way, I get no warnings/errors during compiling, nor linking.

Edit: Here's a couple of snippets from the preprocessor's output.

int lv_superscope_cleanup (VisPluginData *plugin)
{
 SuperScopePrivate *priv = visual_object_get_private ((((VisObject*) ((plugin)))));

 visual_mem_free_impl (priv, "actor_avs_superscope.c", 195, __PRETTY_FUNCTION__);

 return 0;
}

And:

 priv = ((SuperScopePrivate *) visual_mem_malloc0_impl (((visual_size_t) sizeof (SuperScopePrivate)) * ((visual_size_t) (1)), "actor_avs_superscope.c", 152, __PRETTY_FUNCTION__));

It looks like the macros are being expanded. I'm confused. Is __PRETTY_FUNCTION__ supposed to be expanded?

Interestingly enough, here's the output from strings.

$ strings .libs/actor_avs_superscope.so |grep malloc
visual_mem_malloc0_impl
visual_mem_malloc0
malloc

Chris: I'm just running ld /usr/lib/libvisual-0.6/actor/actor_avs_superscope.so.

And here's the output from nm:

$ nm actor_avs_superscope.o |grep malloc
         U visual_mem_malloc0_impl

$ nm actor_avs_superscope.o |grep free
         U visual_mem_free_impl
         U visual_palette_free_colors
4

4 回答 4

3

C 代码中的宏不会在已编译的可执行文件中产生符号。可能正在发生的事情是您正在编译的某些代码没有#include这些宏,因此编译器推断它们是函数,并编译了对它们的调用。您可以使用-Walland-Werror来使未定义函数的调用无法编译。

于 2010-01-18T19:15:14.387 回答
1

Feels like it's not reading your #defines -- try printing a message inbetween them just to check.

Also check the order of compilation of your files; does the call to visual_mem_new0 come after the #defines?

于 2010-01-18T09:16:17.720 回答
1

在链接之前的预处理阶段处理宏。因此,如果链接编辑器向您发出有关宏名称的警告,则宏没有展开。

要查看预处理的结果,可以使用 /E 标志。如果您的宏已扩展,您将看到以下行:

visual_mem_free (priv);

改为:

visual_mem_free_impl(priv, "filename.c", 32, "main");

更新

从您的 nm/strings 输出中,文件 actor_avs_superscope.o 不是问题所在。还有哪些其他对象 (.o) 文件和静态档案 (.a) 用于创建 actor_avs_superscope.so?您应该在所有这些上运行 nm 以查找其中有未扩展的宏名称的人。

于 2010-01-18T20:30:24.213 回答
0

您的第一个错误是针对已安装的库,/usr/lib/libvisual-0.6/actor/actor_avs_superscope.so看起来您正在查看项目中的本地库strings .libs/actor_avs_superscope.so。尝试对 in 运行字符串/usr/lib,您可能会看到问题。

我要么安装你更新的库版本,要么在你运行它时将它的目录放在 LD_LIBRARY_PATH 中,比如$ LD_LIBRARY_PATH=./lib ./your_executable.

于 2010-01-18T21:20:32.057 回答