1
votes

I'm using swig to produce a python C++ interface such that I can make scripts in python to call my c++ functions. I've gotten as far as:

swig -c++ python filename.i

gcc -c filename.cpp filename_wrap.cxx -shared -Ic:\includepath

Where the include path is my python27's include directory.

Upon attempting to compile with gcc, I get a whole slew of errors stating that many of my functions were declared as extern and now static. In the original cpp file, I had declared some of my functions as static. I have never declared anything as extern. What could this be caused by?

This is my interface file

/*  Interface */
%module ReadWrite
%{
    #include "ReadWrite.h"

%}
%include "ReadWrite.h"

A snippet of header file (names changed) looks like this (nothing is declared as extern)

static bool myfunc1(void);

static bool myfunc2 (type1 *Entry, type2 *Block, type2 *Data);

static bool myfunc3 (type2 *Data, type3 **Records, type2 **Header);

type4 myfunc4 (void) ;

When I do a gcc -c ReadWrite.cpp ReadWrite_wrap.cxx -shared -Ic:\includepath, I'll get errors like from gcc:

ReadWrite.cpp:682:79: error: 'bool myfunc3 (type2 *Data, type3 **Records, type2 **Header)' was declared 'extern' and later 'static'

1
Without some snippets of the offending code I don't think it's possible to make an intelligible guess. - Chris Eberle
Will add code to main post. A moment. - limenuke
Yes, but maybe even the exact compiler error? - Chris Eberle

1 Answers

7
votes

The fact that they appear in a header as a prototype implicitly define them as an extern function. However you're ALSO declaring them as static.

Given the C++ tag, I'm going to make an assumption here, so please pardon me if you already know this and it comes off as patronizing. static in C does something completely different than C++. In C++, static means that a particular method doesn't belong to an instance of a class, and can be called by anyone at any time. In C, the static keyword means, "this function is only visible within the scope of this file". So when you declare something static, you're basically forbidding anyone outside of that file from using it (think of it as the C equivalent of private).

So if that's not your intention, don't declare it static.