Question

So, here is the problem.

I have compiled some object files, using gcc -c, and I have cloned them using obj-copy. If the a function of the initial object file was named foo(), then the resulting function names in the cloned objects are: foo1(); foo2(); foo3();

Then, I link those 3 objects, with another file, that contains the main method, and I can invoke each of the function variants by using e.g. foo2();. This work perfectly fine!

However, if I try to create a function pointer to point to those functions by using:

functionPtr=&foo1; \\ tried also w/o the &

then, I get:

error: 'foo2' undeclared (first use in this function)

Any ideas? Does this have to do with the linking?

Was it helpful?

Solution

foo2 must be declared in a header file somewhere. You've cloned the object files, but the C compiler still needs something to tell it that there's a function called foo2 and what its signature is. If you have a declaration somewhere for the original foo, just make a copy of that and change the name to foo2, and make sure the header is #include'd in your source.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top