我发现了一些类似的问题(如这个,那个或这个),但没有人帮我解决我的问题.我有一个*.so文件(来自gnss-sdr的核心),如下所示:
$nm libgnss_system_parameters_dyn.so | c++filt |grep Gps_Eph
Run Code Online (Sandbox Code Playgroud)
包含符号Gps_Ephemeris::Gps_Ephemeris(),它应该是一个构造函数.
我写了一些最小的代码:
#include <iostream>
#include <core/system_parameters/gps_ephemeris.h>
int main(int argc,const char* argv[])
{
Gps_Ephemeris ge;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译的是:
g++ main.cpp -std=c++0x -I some_include_path -L some_lib_path -l gnss_system_parameters_dyn`
Run Code Online (Sandbox Code Playgroud)
然后链接器抱怨:
/tmp/ccHCvldG.o: In function `main':
main.cpp:(.text+0x33): undefined reference to `Gps_Ephemeris::Gps_Ephemeris()'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我也尝试过cmake,但它生成的行类似于它(它只是-rdynamic在链接之前添加),它仍然生成完全相同的链接器错误.
请注意,库和我的最小代码都使用相同的编译器(g ++ - 5)进行编译,具有完全相同的标志和相同的c ++ 0x标准.
解决Maxim Egorushkin的答案:
nm --demangle --defined-only --extern-only libgnss_system_parameters.so |grep …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码.
const int N = 100;
const float alpha = 0.9;
Eigen::MatrixXf myVec = Eigen::MatrixXf::Random(N,1);
Eigen::MatrixXf symmetricMatrix(N, N);
for(int i=0; i<N; i++)
for(int j=0; j<=i; j++)
symmetricMatrix(i,j) = symmetricMatrix(j,i) = i+j;
symmetricMatrix *= alpha;
symmetricMatrix += ((1-alpha)*myVec*myVec.adjoint());
Run Code Online (Sandbox Code Playgroud)
它基本上实现了指数平均.我知道最后一行可以通过以下方式进行优化.
symmetricMatrix_copy.selfadjointView<Eigen::Upper>().rankUpdate(myVec, 1-alpha);
Run Code Online (Sandbox Code Playgroud)
我想知道我是否能以有效的方式结合最后两行.总之,我想计算 A = alpha*A+(1-alpha)*(x*x').
OpenCV中的文件上cv::Mat似乎表明,有在那一刻没有move构造函数,所以像cv::Mat A=std::move(some_other_cv_mat)没有太大的意义。我对这个问题的当前(和天真的)解决方案是从 派生一个类cv::Mat,为此我实现了一个移动构造函数,如下所示:
namespace cv
{
//matrix object derived from cv::Mat
class Mvbl_Mat final: public Mat
{
public:
//constructors
Mvbl_Mat(){};
Mvbl_Mat(int rows, int cols, int type, const Scalar &s):Mat(rows, cols, type, s){}
//destructor
~Mvbl_Mat(){};
//move constructor
Mvbl_Mat(Mvbl_Mat && other) noexcept
{
this->data=other.data;
other.data=nullptr;
}
//move assignment operator
Mvbl_Mat & operator=(Mvbl_Mat && other)
{
this->data=other.data;
other.data=nullptr;
return *this;
}
};
}
Run Code Online (Sandbox Code Playgroud)
虽然这适用于我目前面临的有限问题,但显然存在许多限制,并且解决方案远非理想。那么,模拟移动语义的最佳方法是cv::Mat什么?
我正在尝试读取一个二进制文件,并且需要确定其大小,但无论我尝试过什么方法,我得到的大小都是零。
例如:
fstream cbf(address, ios::binary | ios::in | ios::ate);
fstream::pos_type size = cbf.tellg(); // Returns 0.
char* chunk = new char[size];
cbf.read(chunk, size);
//...
Run Code Online (Sandbox Code Playgroud)
如果我要使用以下内容:
#include <sys/stat.h>
struct stat st;
stat(address.c_str(),&st);
int size = st.st_size;
Run Code Online (Sandbox Code Playgroud)
大小仍然为零。我也尝试过以下方法,但它仍然为零。
File* fp;
fp = open(address.c_str(), "rb");
Run Code Online (Sandbox Code Playgroud)
如何获取文件的大小?
感谢您的回复...我已经确定了问题:我试图访问的二进制文件是在执行期间创建的,而我只是忘记在尝试读取它之前关闭它...
我发现了一些类似的问题(例如 这个),但没有一个真正回答我的问题.请考虑以下代码段:
template<unsigned int rows, unsigned int cols,typename arrtype>
class Variance
{
double f(const arrtype &);
};
template<unsigned int rows, unsigned int cols>
double Variance<rows,cols,Eigen::Matrix<double,rows,cols>>
::f(const Eigen::Array<double,rows,cols> & M)
{
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
正如您在专业化中所看到的,类型arrtype将取决于rows和cols.上面的代码导致编译器错误(g ++ 5.4.0):
invalid use of incomplete type ‘class Variance<rows, cols, Eigen::Matrix<double, rows, cols> >
Run Code Online (Sandbox Code Playgroud)
我已经尝试typename arrtype<rows, cols>过模板声明,但后来抱怨这arrtype 不是一种类型,这是有道理的.
使用依赖于其他模板类型的模板化类型的正确方法是什么?
如此处所述,std::bitset::operator^=返回*this.从与从运营商的"通常"的解释,如+=, |=, *=人们可以合理地假定给定的std::bitset实例(具有相同的尺寸)a和b,表达(a^=b).count() 将存储按位的结果XOR在操作a,并且count() 将返回在比特数a即被设置为true.但是,如下面的最小示例所示,发生了意外情况:
#include <iostream>
#include <bitset>
int main()
{
constexpr unsigned int N=6;
std::bitset<N> a;
std::bitset<N> b;
a.flip();//111111
b[0]=1;
b[4]=1;//b is now 010001 (assuming least significan bit on the right end of the string)
std::cout<<"a=="<<a.to_string()<<std::endl;
std::cout<<"b=="<<b.to_string()<<std::endl;
std::cout<<"(a xor b) to string=="<<(a^=b).to_string()<<std::endl;
//Here is the unexpected part!
std::cout<<"(a xor b) count=="<<(a^=b).count()<<std::endl;
//Note that the …Run Code Online (Sandbox Code Playgroud) 我有一些遗留代码,我正在用"更新"的编译器构建并运行一些对我来说没有意义的静态const double初始化错误.这就是我所拥有的:
//header.h
class myclass
{
private:
static const double foo = 3.1415;
static const double bar = 12345.0 * foo;
};
Run Code Online (Sandbox Code Playgroud)
用gcc版本4.3.3编译此代码时 - 我看到以下错误:
foo cannot appear in a constant-expression
Run Code Online (Sandbox Code Playgroud)
我已经将其解释为不是静态初始化顺序惨败,因为我相信内部数据类型具有良好定义的初始化顺序 - 尤其是当它们位于同一个类中时.作为测试,我已经尝试static_cast< double >过表达式,但是这会产生另一个错误,指出在const表达式中只允许使用整数类型转换.