1

I wanted to test snappy library, but while compiling my project I have 2 errors:

1>main.obj : error LNK2019: unresolved external symbol "bool __cdecl snappy::Uncompress(char const *,unsigned int,class std::basic_string,class std::allocator > *)" (?Uncompress@snappy@@YA_NPBDIPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "unsigned int __cdecl snappy::Compress(char const *,unsigned int,class std::basic_string,class std::allocator > *)" (?Compress@snappy@@YAIPBDIPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main

fatal error LNK1120: 2 unresolved externals

#pragma comment(lib,"snappy32.lib")

#include <snappy.h>
#include <snappy-c.h>
#include <snappy-sinksource.h>

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{
    string buffer = "0=EURCHF|1=1.21541|2=1.21547|5=20140318T075959.728388|15=1.21547|16=1.21551|17=1.21553|18=1.21555|19=1.21556|20=1.21559|21=1.21576|22=1.21584|115=1000000|116=2000000|117=3500000|118=3000000|119=5000000|120=9000000|121=1000000|122=2000000|315=1.21541|316=1.21537|317=1.21535|318=1.21533|319=1.21532|320=1.21531|321=1.21529|322=1.21518|323=1.2151|324=1.21489|415=500000|416=1000000|417=1000000|418=5000000|419=5000000|420=2000000|421=9000000|422=500000|423=2000000|424=7000000|720=500000|721=1000000";
    string output;
    size_t compressedSize = snappy::Compress(buffer.data(),buffer.size(),&output);
    printf("%s",output.c_str());
    string uncompressedBuffer;
    bool result = snappy::Uncompress(output.data(),output.size(),&uncompressedBuffer);
    printf("%s\n",uncompressedBuffer.c_str());
    return 0;
}

I have added directory with lib and snappy32.lib in my project properties.

4

1 回答 1

0

我有同样的问题。默认情况下,snappy 似乎没有正确构建为静态库。

我的解决方案是:打开 msvc 项目(在https://cdn.machinezoo.com/download/snappy/snappy-windows-1.1.1.8.7z找到它);在属性中,设置:项目默认值 -> 配置类型 -> 静态库 (.lib)。

为您的应用程序使用正确的配置编译此项目;编译后的 .lib 然后由应用程序正确链接,您可以调用缺少的方法。希望这可以帮助!

于 2019-02-05T11:08:54.207 回答