[英]How to build snappy on windows 10 in VS2015?
我在这里下载了 snappy 1.1.8,然后按照自述文件在我的电脑上编译,
mkdir 构建
cd build && cmake../
然后我在VS2015中打开.sln
文件,构建lib
,没有错误。
然后我写一个像下面这样的例子,并将lib
添加到我的项目中:
class Sna
{
public:
Sna(string &data) :data_(data)
{
}
void compress()
{
auto start = high_resolution_clock::now();
snappy::Compress(data_.data(), data_.size(), &compressed_);
auto end = high_resolution_clock::now();
cout << "compress use time: " << duration_cast<microseconds>(end - start).count() << " microseconds" << endl;
}
void unCompress()
{
auto start = high_resolution_clock::now();
snappy::Uncompress(compressed_.data(),compressed_.size(),&recoverd_);
auto end = high_resolution_clock::now();
cout << "unCompress use time: " << duration_cast<microseconds>(end - start).count() << " microseconds" << endl;
}
bool check()
{
return !data_.compare(recoverd_) ? true : false;
}
double ratio()
{
int temp = int(data_.length() - compressed_.length());
double d = (double)temp / data_.length();
return d * 100;
}
private:
string data_, compressed_, recoverd_;
};
int main()
{
//read data from file
//...
Sna sna(data);
sna.compress();
sna.unCompress();
return 0;
}
compress
function 是可以的,但是当执行unCompress
function 时,程序崩溃了,它给了我这个错误:
0xC000001D:非法指令。
在snappy.cc
第 720 行:
#if SNAPPY_HAVE_BMI2
return _bzhi_u32(v, 8 * n);
我努力了:
Enable Enhanced Instruction Set
为Advanced Vector Extensions 2 (/arch:AVX2)
,但仍然存在其他问题。不知道是哪一步做错了? 以及如何解决这个问题?
感谢@rpress,解决了这个问题。
找到文件CMakeLists.txt
并注释掉第 118 到 112 行,如下所示
# check_cxx_source_compiles("
# #include <immintrin.h>
# int main() {
# return _bzhi_u32(0, 1);
# }" SNAPPY_HAVE_BMI2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.