python - Swig 记得旧的函数声明 (gnuradio)。编辑函数的返回类型会导致错误
问题描述
当我尝试更改我编写的库函数的声明时,我观察到一些奇怪的行为。我想将函数的返回类型calc_sequence
从int
to更改为,vector<gr_complex>
但在生成 swig.py 文件时会忽略这些更改
我的标题是:
namespace gr {
namespace Channel_prediction {
/*!
* \brief <+description+>
*
*/
class CHANNEL_PREDICTION_API Chpr_lib
{
public:
Chpr_lib();
~Chpr_lib();
static std::vector<gr_complex> calc_sequence(int Nzc, int M); // return type has just been changed from int
private:
};
} // namespace Channel_prediction
} // namespace gr
源文件Chpr_lib.cc
是:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include <Channel_prediction/Chpr_lib.h>
namespace gr {
namespace Channel_prediction {
Chpr_lib::Chpr_lib()
{
}
Chpr_lib::~Chpr_lib()
{
}
std::vector<gr_complex> Chpr_lib::calc_sequence(int Nzc, int M)
{
std::vector<gr_complex> sequence;
gr_complex arg=4;
sequence.push_back(arg);
return sequence;
}
} /* namespace Channel_prediction */
} /* namespace gr */
当我make
现在重新运行时,我收到这个错误,告诉我我无法投射vector<gr_complex>
到int
Scanning dependencies of target gnuradio-Channel_prediction
[ 6%] Building CXX object lib/CMakeFiles/gnuradio-Channel_prediction.dir/Chpr_lib.cc.o
[ 13%] Linking CXX shared library libgnuradio-Channel_prediction.so
[ 20%] Built target gnuradio-Channel_prediction
[ 20%] Built target pygen_apps_9a6dd
[ 26%] Built target doxygen_target
[ 40%] Built target _Channel_prediction_swig_doc_tag
[ 53%] Built target Channel_prediction_swig_swig_doc
[ 60%] Built target Channel_prediction_swig_swig_compilation
Scanning dependencies of target Channel_prediction_swig
[ 66%] Building CXX object swig/CMakeFiles/Channel_prediction_swig.dir/CMakeFiles/Channel_prediction_swig.dir/Channel_prediction_swigPYTHON_wrap.cxx.o
/home/student/Documents/channel-prediction-with-gnuradio/OOT/gr-Channel_prediction/build/swig/CMakeFiles/Channel_prediction_swig.dir/Channel_prediction_swigPYTHON_wrap.cxx: In function ‘PyObject* _wrap_Chpr_lib_calc_sequence(PyObject*, PyObject*, PyObject*)’:
/home/student/Documents/channel-prediction-with-gnuradio/OOT/gr-Channel_prediction/build/swig/CMakeFiles/Channel_prediction_swig.dir/Channel_prediction_swigPYTHON_wrap.cxx:8640:78: error: invalid cast from type ‘std::vector<std::complex<float> >’ to type ‘int’
8640 | result = (int)gr::Channel_prediction::Chpr_lib::calc_sequence(arg1,arg2);
| ^
make[2]: *** [swig/CMakeFiles/Channel_prediction_swig.dir/build.make:63: swig/CMakeFiles/Channel_prediction_swig.dir/CMakeFiles/Channel_prediction_swig.dir/Channel_prediction_swigPYTHON_wrap.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:408: swig/CMakeFiles/Channel_prediction_swig.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
当然,它不应该尝试将其转换为int
. 该Channel_prediction_swig.py
文件仍然错误地将目标类型定义calc_sequence
为int
:
class Chpr_lib(object):
"""Proxy of C++ gr::Channel_prediction::Chpr_lib class."""
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self):
"""__init__(gr::Channel_prediction::Chpr_lib self) -> Chpr_lib"""
this = _Channel_prediction_swig.new_Chpr_lib()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _Channel_prediction_swig.delete_Chpr_lib
__del__ = lambda self: None
def calc_sequence(Nzc: 'int', M: 'int') -> "int":
"""calc_sequence(int Nzc, int M) -> int"""
return _Channel_prediction_swig.Chpr_lib_calc_sequence(Nzc, M)
calc_sequence = staticmethod(calc_sequence)
Chpr_lib_swigregister = _Channel_prediction_swig.Chpr_lib_swigregister
Chpr_lib_swigregister(Chpr_lib)
def Chpr_lib_calc_sequence(Nzc: 'int', M: 'int') -> "int":
"""Chpr_lib_calc_sequence(int Nzc, int M) -> int"""
return _Channel_prediction_swig.Chpr_lib_calc_sequence(Nzc, M)
swig 必须在某个地方注意到函数的原始声明并继续重用它。我试图删除整个构建文件夹并重建所有内容。我还通过 grep 在项目中搜索了函数声明的其他提及,但一无所获。
这里的Channel_prediction_swig.i
文件:
/* -*- c++ -*- */
#define CHANNEL_PREDICTION_API
%include "gnuradio.i" // the common stuff
//load generated python docstrings
%include "Channel_prediction_swig_doc.i"
%{
#include "Channel_prediction/zadoffchu_c.h"
#include "Channel_prediction/Chpr_lib.h"
%}
%include "Channel_prediction/zadoffchu_c.h"
GR_SWIG_BLOCK_MAGIC2(Channel_prediction, zadoffchu_c);
%include "Channel_prediction/Chpr_lib.h"
不过那里也没有魔法。希望有人以前偶然发现过这个。它很容易重新创建。Chpr_lib 已添加到带有gr_modtool add noblock
. 之后,我首先添加了calc_sequence
带有 returntype的函数,int
编译所有内容都没有问题,并编辑了 returntype 以解决std::vector<gr_complex>
产生的问题。
我不确定Channel_prediction_swig.py是在什么时候创建的。我使用cmake -DCMAKE_INSTALL_PREFIX=~/prefix-3.8 -DCMAKE_BUILD_TYPE=Debug ../
然后make
出现 swig.py 文件。所有的 cmake 文件都是由 gnuradio 通过 pybombs 附带的 gr_modtool 创建的。前缀 Python 版本为:3.8.5 PyBOMBS 版本 2.3.4,系统为 #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64。
这是我在删除构建文件夹后运行 cmake 时得到的:
-- The CXX compiler identification is GNU 9.3.0
-- The C compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found LOG4CPP: /usr/lib/x86_64-linux-gnu/liblog4cpp.so
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'gmp'
-- Found gmp, version 6.2.0
-- Found GMP: /usr/lib/x86_64-linux-gnu/libgmpxx.so
-- Checking for module 'mpir >= 3.0'
-- No package 'mpir' found
-- Could NOT find MPIR (missing: MPIRXX_LIBRARY MPIR_LIBRARY MPIR_INCLUDE_DIR)
-- Found MPLIB: /usr/lib/x86_64-linux-gnu/libgmpxx.so
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.71.0") found components: date_time program_options filesystem system regex thread unit_test_framework
-- Found VOLK: Volk::volk
-- User set python executable /usr/bin/python3
-- Found PythonInterp: /usr/bin/python3 (found version "3.8.5")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found suitable exact version "3.8.5")
-- Found Git: /usr/bin/git
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen missing components: dot
-- Using install prefix: /home/student/prefix-3.8
-- Building for version: v1.0-compat-xxx-xunknown / 1.0.0git
-- No C++ unit zadoffchu_tapss... skipping
--
-- Checking for module SWIG
-- Found SWIG version 3.0.12.
-- Found SWIG: /usr/bin/swig3.0
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found version "3.8.5")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/student/Documents/channel-prediction-with-gnuradio/OOT/gr-Channel_prediction/build
解决方案
我还没有找到问题的根源,但我找到了一个有效的解决方案,并且很好地引导了可以找到问题的地方。
Pybombs 安装前缀包含一个文件夹include/
,其中包含来自每个模块的头文件。如果我删除文件夹并重建模块,错误就会消失:
/prefix-3.8/include/Channel_prediction/
据我了解,make 和 cmake 在构建模块时不应引用安装目录中的文件,因为它们包含过时的信息。在我手头有一点时间的情况下,我将进一步调查错误发生的确切位置。
推荐阅读
- mysql - 通过脚本执行重新排列工作表布局以符合 sql 导入过程
- kendo-ui - 剑道 datePicker 在星期三禁用即将到来的周末
- c++ - 构建错误“没有用于调用 'sg_ofstream::open(const wchar_t*, std::ios_base::openmode&) 的匹配函数”
- powershell - 如何使用 txt 列表复制文件以定义文件名的开头
- c++ - 如何使用递归函数返回数组中整数的索引?
- java - 有没有办法检测手机指纹上的手指触摸?
- powershell - 无法替换字符串中的“$”
- java - Period.between 不包括 Java 中的最后一天
- reactjs - 背景颜色和边框半径属性在 React Native 中无法协同工作 - Android
- android - 获取 jsonArray for 循环之外的值