Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

c++ - Compile a C library with Visual Studio 2010

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 !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...