3

I got here a C library written by someone else, with a very nice way to compile it on a Mac and generate a ruby wrapper.

I am on Windows, and I need to generate a wrapper for .Net. I know absolutely nothing about C or C++.

  • I have created a .i file that just %include the .h file, and used Swig to generate C# files and a xxx_wrapper.c file.
  • I have created an empty C++ project with Visual Studio 2010, and included all the .h and .c files of the project (except the ones to generate the ruby wrapper)
  • Now when I try to compile, I get a few compilation errors each time there is an inline function:

    file.c(54): error C2054: '(' expected after 'inline'
    file.c(54): error C2085: 'swap_img' : is not in the formal parameters list
    file.c(54): error C2143: syntax error: missing ';' before '{'

I have read here that it might be because VS tries to compile my c files as c++. But how do I do that ? I can't change anything in the code (and I wouldn't try), so I just need to "fix" the project.

Thanks !

Community
  • 1
  • 1
thomasb
  • 5,816
  • 10
  • 57
  • 92

1 Answers1

3

In the version of the C language that's supported by Visual Studio 2010, there is no word inline. Only C++ has inline. I don't think inline became a part of C until the very latest version of the C standard (C11), which nobody supports yet.

Instead, you should use the word __inline, which means the same thing. The underscores imply that this is an "extension," something that's not part of standard C.

Alternatively, you could put #define inline __inline at the start of each file, or in a .h header file which is #included at the beginning. That would automatically translate the word inline to __inline each time it appears.

(It's likely that the person who wrote that code was using a different compiler, one which chose to add inline without the underscores. It's still an "extension" because it's not part of Standard C.)

librik
  • 3,738
  • 1
  • 19
  • 20
  • ok so if I add the underscores, will it still compile in the other's compiler ? (I think it's make but I don't know which version) – thomasb Jun 26 '14 at 16:00
  • If the other compiler is GCC, then yes. But the trouble with extensions is that they're not "portable," meaning there's no guarantee they'll work everywhere. You could surround the `#define inline __inline` with `#ifdef _MSC_VER` ... `#endif` to ensure that the `__inline` only applies to Microsoft C. – librik Jun 26 '14 at 16:02
  • The reason for those specific error messages is that it thinks you want `inline` to be the name of the function. (Since it doesn't know the word as part of C.) So it says things like "expected a ( after inline" -- when you're writing a function you put a ( after the name. – librik Jun 26 '14 at 16:07
  • Thanks ! I have another error now, but this one is gone ! :) – thomasb Jun 26 '14 at 16:14