我之前已经问过这个问题,但我找不到有用的解决方案。完整的错误是:
Executing: "/home/mint/Documents/test_sensor/cycl_test/top_block.py"
Using Volk machine: avx_64_mmx_orc
Traceback (most recent call last):
File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 87, in <module>
tb = top_block()
File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 61, in __init__
self.cycl_MME_cpp_0 = cycl.MME_cpp(1000, 16, 0.1)
AttributeError: 'module' object has no attribute 'MME_cpp'
我从以前的问题中找到了一些可能的原因:
函数参数不匹配(包括.cc和.h中的引用函数)
swig问题
.xml文件中的回调
nm -C -u libgnuradio-.so
我检查了前3个原因,但我不确定如何使用最后的方法找出未定义的符号。部分结果如下:
U gsl_linalg_SV_decomp
U gsl_matrix_alloc
U gsl_matrix_set
U gsl_matrix_set_zero
U gsl_vector_alloc
U gsl_vector_get
这是否意味着所有gsl函数都未定义?如果是这样,我该如何处理呢?
除了四个原因外,还有其他关于我的问题的提示吗?
感谢您的帮助。
附录:
1.MME_cpp_impl.cc
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "MME_cpp_impl.h"
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>
namespace gr {
namespace cycl {
MME_cpp::sptr
MME_cpp::make(int Ns, int M, float Pfa)
{
return gnuradio::get_initial_sptr
(new MME_cpp_impl(Ns, M, Pfa));
}
/*
* The private constructor
*/
MME_cpp_impl::MME_cpp_impl(int Ns, int M, float Pfa)
: gr::sync_block("MME_cpp",
gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(1, 1, sizeof(float))),
d_Ns(Ns), d_M(M), d_Pfa(Pfa)
{}
/*
* Our virtual destructor.
*/
MME_cpp_impl::~MME_cpp_impl()
{
}
/*This function gives the CDF value for the pfa in input*/
float
TracyWidom (float p){
float pd, tw;
tw = 0.45;
pd = 1 - p;
if (pd >= 0.01 && pd <= 0.05){
tw = 18*(pd - (17/75)); printf("a - %f\n", tw);
}else if (pd >= 0.05 && pd <= 0.1){
tw = 8*(pd - (179/400)); printf("b - %f\n", tw);
}else if (pd >= 0.1 && pd <= 0.3){
tw = (87/20)*(pd - (643/870)); printf("c - %f\n", tw);
}else if (pd >= 0.3 && pd <= 0.5){
tw = (16/5)*(pd - (287/320)); printf("d - %f\n", tw);
}else if (pd >= 0.5 && pd <= 0.7){
tw = (17/5)*(pd - (297/340)); printf("e - %f\n", tw);
}else if (pd >= 0.7 && pd <= 0.9){
tw = (5.2)*(pd - (0.813)); printf("f - %f\n", tw);
}else if (pd >= 0.9 && pd <= 0.95){
tw = (53/5)*(pd - (909/1060)); printf("g - %f\n", tw);
}else if (pd >= 0.95 && pd <= 1){
tw = 26*(pd - (593/650)); printf("h - %f\n", tw);
}else{
printf ("wrong pfa value: it must be between 0 and 1\n");
printf ("the pfa value standard is 0.1\n");
tw = (53/5)*(0.9 - (909/1060));
}
return tw;
}
/*this function calculates the threshold for the test
the inputs are:
ns = numbers of samples/L;
L = length of the correlation function;
pfa = probability of false alarm*/
float
gamma (int ns, int L, float tw){
float A, B, C, ratio1, ratio2, g;
A = sqrt(ns)+sqrt(L*ns);
B = sqrt(ns)-sqrt(L*ns);
C = ns*ns*L;
ratio1 = pow(A,2)/pow(B,2);
ratio2 = 1+( pow(A,-0.667) / pow(C,0.167) )*tw;
g = ratio1*ratio2;
return g;
}
/*This function makes the detection test*/
float
test (float r, float t){
float decision;
if(r > -1){
if(r <= t){
decision = 0;
}
else{
decision = 1;
}
}
return decision;}
//-------------end functions-----------
int
MME_cpp_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
//float cov;
//int ninputs = input_items.size ();
//for(int i=0; i<noutput_items*Ns; ++i){
// cov = compute_convariance(in[i]);
//int lenght = floor(d_samples / d_L) * d_L;
float vett[d_Ns];
int lenght = floor(d_Ns / d_M) ;
int p, j, k=0;
float thr, lmax, lmin, ratio=-1, TW, mem=0;
// char c[1];
gsl_matrix * hankel = gsl_matrix_alloc (lenght,d_M);
gsl_matrix * V = gsl_matrix_alloc (d_M,d_M);
gsl_vector * S = gsl_vector_alloc (d_M);
gsl_vector * temp = gsl_vector_alloc (d_M);
//FILE *story;
gsl_matrix_set_zero (hankel);
TW = TracyWidom (d_Pfa);
thr = gamma(lenght, d_M, TW); //calculate the threshold
for (int i = 0; i < noutput_items; i++){
vett[k]=in[i];
k++;
if (k >= lenght*d_M){
k = 0;
// story = fopen("filestory.txt", "a");
for( p=0; p<lenght; p++ ){
for( j=0; j<d_M; j++ ){
gsl_matrix_set (hankel, p, j, vett[p+j]);
}
}
gsl_linalg_SV_decomp (hankel, V, S, temp);//using SDV to calculate eigenvalue
lmax = gsl_vector_get(S, 0);//maximal eigenvalue
lmin = gsl_vector_get(S, (d_M -1));//minimal eigenvalue
ratio = lmax/lmin;
mem = test(ratio, thr);
//fprintf(story, "%f - ratio=%f - soglia=%f\n ", mem, ratio, thr);
//fclose(story);
}
out[i] = mem;
}
// Tell runtime system how many output items we produced.
return noutput_items;
}
} / * namespace cycl / } / namespace gr * /
2.MME_cpp_impl.h
#ifndef INCLUDED_CYCL_MME_CPP_IMPL_H
#define INCLUDED_CYCL_MME_CPP_IMPL_H
#include <cycl/MME_cpp.h>
namespace gr {
namespace cycl {
class MME_cpp_impl : public MME_cpp
{
private:
int d_Ns, d_M;
float d_Pfa;
public:
MME_cpp_impl(int Ns, int M, float Pfa);
~MME_cpp_impl();
int Ns() const { return d_Ns; }
void set_Ns(int Ns) { d_Ns = Ns; }
int M() const { return d_M; }
void set_M(int M) { d_M = M; }
float Pfa() const { return d_Pfa; }
void set_Pfa(float Pfa) { d_Pfa = Pfa; }
// Where all the action really happens
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
//float compute_covariance(float & d, int i, int j);
friend float TracyWidom (float p);
friend float gamma (int ns, int L, float tw);
friend float test (float r, float t);
};
float TracyWidom (float p);
float gamma (int ns, int L, float tw);
float test (float r, float t);
} // namespace cycl
} // namespace gr
#endif /* INCLUDED_CYCL_MME_CPP_IMPL_H */
3.MME_cpp.h
#ifndef INCLUDED_CYCL_MME_CPP_H
#define INCLUDED_CYCL_MME_CPP_H
#include <cycl/api.h>
#include <gnuradio/sync_block.h>
namespace gr {
namespace cycl {
/*!
* \brief <+description of block+>
* \ingroup cycl
*
*/
class CYCL_API MME_cpp : virtual public gr::sync_block
{
public:
typedef boost::shared_ptr<MME_cpp> sptr;
/*!
* \brief Return a shared_ptr to a new instance of cycl::MME_cpp.
*
* To avoid accidental use of raw pointers, cycl::MME_cpp's
* constructor is in a private implementation
* class. cycl::MME_cpp::make is the public interface for
* creating new instances.
*/
static sptr make(int Ns, int M, float Pfa);
virtual int Ns() const = 0;
virtual void set_Ns(int Ns) = 0;
virtual int M() const = 0;
virtual void set_M(int M) = 0;
virtual float Pfa() const = 0;
virtual void set_Pfa(float Pfa) = 0;
};
} // namespace cycl
} // namespace gr
#endif /* INCLUDED_CYCL_MME_CPP_H */
4.cycl_MME_cpp.xml
<?xml version="1.0"?>
<block>
<name>MME_cpp</name>
<key>cycl_MME_cpp</key>
<category>cycl</category>
<import>import cycl</import>
<make>cycl.MME_cpp($Ns, $M, $Pfa)</make>
<callback>set_Ns($Ns)</callback>
<callback>set_M($M)</callback>
<callback>set_Pfa($Pfa)</callback>
<param>
<name>Number of samples</name>
<key>Ns</key>
<type>int</type>
</param>
<param>
<name>Length of correlation function</name>
<key>M</key>
<type>int</type>
</param>
<param>
<name>false probability</name>
<key>Pfa</key>
<type>float</type>
</param>
<sink>
<name>in</name>
<type>float</type>
</sink>
<source>
<name>out</name>
<type>float</type>
</source>
</block>
答案 0 :(得分:4)
开发块时遇到了同样的问题。我注意到CMake脚本抱怨swig库丢失了。虽然这不是一个致命的错误,但没有它就行不通。
安装swig后我可以使用我的模块:sudo apt-get install swig
答案 1 :(得分:2)
这可能是由于默认情况下安装了.so的路径。我最近遇到了这个问题,发现默认情况下/ usr / local / lib不在我的/etc/ld.so.conf中(Arch Linux)。更新/etc/ld.so.conf后,我跑了:
sudo ldconfig
问题已解决。