1
votes

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.

1
double check that this is correct lib and it contains Compress & Uncompress functions4pie0
try to use something else from referenced library. If it works then maybe Compress is not static?4pie0

1 Answers

0
votes

I've had the same issue. It looks like by default snappy is not correctly built as a static lib.

My solution is: opene the msvc project (find it at https://cdn.machinezoo.com/download/snappy/snappy-windows-1.1.1.8.7z); in properties, set: Project Defaults -> Configuration Type -> Static library (.lib).

Compile this project with correct configuration for your application; the compiled .lib is then linked correctly by the application and you can call the missing methods. Hope this helps!