swig / www

Web pages at http://www.swig.org
10 stars 17 forks source link

Document %include behavior for __declspec preprocessor directives. #3

Closed chriskrycho closed 9 years ago

chriskrycho commented 9 years ago

Add a short paragraph and example of how to handle the way Microsoft recommends to wrap __declspec definitions in preprocessor macros and supply them in a common header file.

wsfulton commented 9 years ago

Thanks. The most common solution to this problem though is just to define the macro to nothing and not bother using windows.i. Would you mind adding a simple example like that to this patch and then I'll apply it?

chriskrycho commented 9 years ago

Sure! Something like this?

Alternately, you can simply undefine the macro and leave out windows.i entirely. Assuming you have defined the preprocessor as BAR_API, you could do something like:

%module bar
#define BAR_API
%include "bar.h"

Assuming that's to your liking, I'll probably get to it on Tuesday or so.

wsfulton commented 9 years ago

Yes, but to be absolutely clear for the reader, also show BAR_API being used in the function, so add in one line of bar.h, something like:

// bar.h
BAR_API void bar_function(int, double);
chriskrycho commented 9 years ago

Very good. I'll add that and expand the example to include bar.h properly as well, like:

%{
#include "bar.h"
%}
ojwb commented 9 years ago

Note that you're actually patching generated files here - the master copies are in the swig repo.

wsfulton commented 9 years ago

Thanks, I've committed this now, see https://github.com/swig/swig/commit/aebc9379ed6dde9c8b903845decb3f017ebb873a and https://github.com/swig/swig/commit/7178bb11d3f089da7b241f49af6eba603a0e636d