3

I use legacy C-Code in my current C++ project by including external headers:

extern "C" {
# include "ANN/ANN_4t70P1.h"
# include "ANN/ANN_4t70P2.h"
# include "ANN/ANN_4t70P3.h"
# include "ANN/ANN_4t70P4.h"
}

The header files look like this:

extern int ANN_4t70P1(float *in, float *out, int init);

static struct {
  int NoOfInput;    /* Number of Input Units  */
  int NoOfOutput;   /* Number of Output Units */
  int(* propFunc)(float *, float*, int);
} ANN_4t70P1REC = {8,3,ANN_4t70P1};

The C-Code is created by an ancient batch-file and cannot be compiled using C++ compilers. Nevertheless, this implementation works fine for Windows and Mac OS. However, when I compile the code using gcc and g++ on Linux and run the application, ANN_4t70P1REC returns incorrect values.

Are there any special linker flags that I missed out when linking the project?

Thanks!

8
  • 7
    ANN_4t70P1REC is an instance of a struct. What do you mean specifically when you say it "returns incorrect values"? Commented Aug 26, 2012 at 16:24
  • 2
    Maybe you need it all to be compiled in 32 bit? Newer machines could be installed as 64 bit so you might need to add the -m32 compiler flag Commented Aug 26, 2012 at 17:19
  • Sorry. Of course I mean the function propFunc within the instance ANN_4t70P1REC that returns unexpected results. The values do not seem to be random values or unallocated memory, but they are completely different from the values that I get with XCode or VC++. Commented Aug 27, 2012 at 9:26
  • 2
    Make a small C-only test program, and check if that returns correct values. Commented Aug 27, 2012 at 10:18
  • You don't have something odd like storing *propFunc in an int somewhere? On 64-bit machines, the pointer will be 8 bytes, not 4. As suggested, try -m32 and see if that makes a difference. Commented Aug 28, 2012 at 0:25

1 Answer 1

1

What do you mean by:

The C-Code is created by an ancient batch-file and cannot be compiled using C++ compilers

Are you linking using object files generated by different compilers? If so, try to inspect your object files with:

readelf -h <objectname>

Check if there is a different ABI. If the code is generated by a very old GCC <3.3/3.4 you can have problems linking with newer versions.

Are you sure you don't have any warnings during the link?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.