【问题标题】:SWIG general questionsSWIG 一般问题
【发布时间】:2017-02-12 20:51:20
【问题描述】:

我正在学习 SWIG,我正在尝试了解一些在查看文档和示例后我无法弄清楚的 c++ 可能情况,这是我的内容:

用例1.h

#ifndef __USECASE1_H__
#define __USECASE1_H__

namespace foo_namespace {
    int usecase1_f1( float b, float c, float *res );
}

#endif

用例1.cpp

int usecase1_f1( float b, float c, float *res )
{
    return 1;
}

用例2.h

#ifndef __USECASE2_H__
#define __USECASE2_H__

extern double usecase2_v1;

int usecase2_f1(int n);
char *usecase2_f2();

#endif

usecase2.cpp

#include <time.h>

double usecase2_v1 = 3.0;

int usecase2_f1(int n) {
    if (n <= 1) return 1;
    else return n * usecase2_f1(n - 1);
}

char *usecase2_f2()
{
    time_t ltime;
    time(&ltime);
    return ctime(&ltime);
}

用例3.h

#ifndef __USECASE3_h__
#define __USECASE3_h__

#include <math.h>

namespace foo_namespace {
    static inline float usecase3_f1( float x )
    {
        return 31.0f;
    }
}

#endif

example1_working.i

%module example

%{
    int usecase1_f1( float b, float c, float *res );
    #include "usecase2.h"
%}

int usecase1_f1( float b, float c, float *res );

%include "usecase2.h"

example2_not_working.i

%module example

%{
    #include "usecase1.h"
    #include "usecase2.h"
%}

%include "usecase1.h"
%include "usecase2.h"

问题

  • example1_working.i 那样明确声明命名空间的函数会起作用,但我想改用标头,这似乎与命名空间混淆了,有什么解决方法吗?
  • 如何在 swig 文件 (usecase3.h) 中包装声明为静态内联的命名空间函数?

【问题讨论】:

    标签: python c++ namespaces inline swig


    【解决方案1】:

    确保在运行时将 -c++ 传递给 swig,默认情况下不启用 C++ 支持。 有关包装 C++ 的更多详细信息,请参见此处 - http://www.swig.org/Doc1.3/SWIGPlus.html

    【讨论】:

      猜你喜欢
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2012-06-16
      • 2012-01-06
      • 1970-01-01
      相关资源
      最近更新 更多