views:

68

answers:

4

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
+1  A: 

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?

lorenzog
+3  A: 

Macros in C code don't result in symbols in compiled executables. Probably what is happening is that some code you are compiling didn't #include these macros, so the compiler inferred that they were functions, and compiled calls to them. You can use -Wall and -Werror to make calls to undefined functions fail to compile.

daf
I had a couple of warnings. Got rid of those, but the symbols are still missing. Also, if the files weren't included, the call to `visual_mem_new0` would fail.
Scott
+1 for -Wall and -Werror. This helps with so many problems.
Mike Nelson
Yeah, I've used them, and they're no help in this situation. Like I said, I got rid of all the warnings/errors. It compiles with those flags, but I still have the initial problem mentioned in this question.
Scott
+1  A: 

Macros are handled during the pre-processing phase which comes before linking. So if the link-editor is giving you warnings about macro names then the macros were not expanded.

To see the results of pre-processing, you can use the /E flag. If your macros have been expanded, you would see the line:

visual_mem_free (priv);

changed to something like:

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

Update

From your nm/strings output, the file actor_avs_superscope.o is not where the problem is. What other object (.o) files and static archives (.a) are used to create actor_avs_superscope.so? You should run nm on all of them in order to find who has the unexpanded macro name in them.

R Samuel Klatchko
I compiled with -E and the output file looks like preprocessor work. I looked through and it appears the macros expanded. I'll update the question with what's in the file.
Scott
That's the only object file building the library. actor_avs_superscope.o
Scott
Oh wait, just found an .a file. That looks like the problem. (It's part of a larger package.)
Scott
Great. If you use `nm -A`, nm will include the name of the object file each symbol is found in.
R Samuel Klatchko
A: 

Your first error is against the installed library, /usr/lib/libvisual-0.6/actor/actor_avs_superscope.so and it looks like you are looking at the local library in your project strings .libs/actor_avs_superscope.so. Try running strings against the one in /usr/lib and you'll probably see the issue.

I'd either Install your updated library version or put it's directory in the LD_LIBRARY_PATH when you run it, something like $ LD_LIBRARY_PATH=./lib ./your_executable.

Mike Nelson
strings on the installed library shows the same thing
Scott