English 中文(简体)
SIP Python/C++ construble 无法以简单示例形式进行编译
原标题:SIP Python/C++ binding fails to compile for simple example

在成功编译了与 SIP 结合的 Python/ C 后, I 想要对 Python/ C++ 做同样的事情。 出于某种原因, 这不起作用 。

这里的文件 :

(bb.cpp) 基本纤维值

#include "(b) 纤维纤维(h)"

int fib1(int n)
{
    if (n <= 0) {
        return 0;
    } else if (n <= 2) {
        return 1;
    } else {
        return fib1(n-1) + fib1(n-2);
    }
}

(b) 纤维纤维(h)

int fib1(int n);

ib.sip 纤维/纤维/纤维/纤维/纤维/纤维/纤维

%Module fib

%Include (b) 纤维纤维(h)

I run the following command to build the intermediate files: sip -c . ib.sip 纤维/纤维/纤维/纤维/纤维/纤维/纤维

到目前为止,一切正常。

现在我要用切片来建立.pid文件。

设置. py 设置

from distutils.core import setup, Extension
import sipdistutils

setup(
  name =  fib ,
  versione =  1.0 ,
  ext_modules=[
    Extension("fib", ["ib.sip 纤维/纤维/纤维/纤维/纤维/纤维/纤维", "(bb.cpp) 基本纤维值"]),
    ],

   cmdclass = { build_ext : sipdistutils.build_ext}
 )

I run the following command: python 设置. py 设置 build

此操作失败, 错误如下 :

build	emp.win32-2.7Releasesipfibcmodule.cpp:29:29: error:  fib1  was not declared in this scope
error: command  gcc  failed with exit status 1

问题会是什么? t c++ 是否应该用作编译器而不是gcc?

感激不尽的帮助!

谨请注意:

戴维·戴维

最佳回答

我找到了一个足够好的解决方案:命名空间。 下次我会读得更好。 我还要提一下, Fibonacci 类的解决方案可以解决问题, 但我觉得这不是令人满意的。

可在文件内容下找到文件 。

(bb.cpp) 基本纤维值

#include "(b) 纤维纤维(h)"

namespace test
{
    int fib1(int n)
    {
        if (n <= 0) {
            return 0;
        } else if (n <= 2) {
            return 1;
        } else {
            return fib1(n-1) + fib1(n-2);
        }
    }
}

(b) 纤维纤维(h)

namespace test
{
    int fib1(int n);
}

ib.sip 纤维/纤维/纤维/纤维/纤维/纤维/纤维

%Module fib

namespace test {
    %TypeHeaderCode
    #include "(b) 纤维纤维(h)"
    %End

    int fib1(int n);
};

设置. py - 没有更改

使用了与前面提到的完全相同的命令。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签