【问题标题】:How to build snappy on windows 10 in VS2015?如何在 VS2015 的 windows 10 上构建 snappy?
【发布时间】:2020-04-06 05:25:38
【问题描述】:

我在here上下载了 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 函数没问题,但是当执行unCompress 函数时,程序崩溃了,它给了我这个错误:

0xC000001D:非法指令。

snappy.cc 720 行:

 #if SNAPPY_HAVE_BMI2
  return _bzhi_u32(v, 8 * n);

我试过了:

  1. 回退 snappy 1.1.7 的版本,对我来说效果很好,没有这个问题。
  2. 编译lib时,将Enable Enhanced Instruction Set设置为Advanced Vector Extensions 2 (/arch:AVX2),但还是有其他问题。

我不知道我做错了哪一步?以及如何解决这个问题?

【问题讨论】:

  • 您的机器不支持 BMI2 指令集。找到 cmake 配置选项 SNAPPY_HAVE_BMI2 并禁用它。
  • rpress 你或许应该回答一下。
  • @rpress 谢谢你帮我解决了这个问题。

标签: c++ compression snappy


【解决方案1】:

感谢@rpress,解决了这个问题。

找到文件CMakeLists.txt.并注释掉第118到112行,如下所示

# check_cxx_source_compiles("
# #include <immintrin.h>
# int main() {
#   return _bzhi_u32(0, 1);
# }" SNAPPY_HAVE_BMI2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 2018-06-18
    • 2020-05-25
    • 2016-02-16
    • 1970-01-01
    相关资源
    最近更新 更多