Reputation: 583
I am trying to compile the example code offered in the github source for the protobuf (adds address and then sends it in a serialized manner to another program that deserializes it and displays it).
The protobuf source code was compiled and installed successfully. (version 3.13.0).
The challenge started when I tried compiling the C++ example file (add_person.cpp).
I created a blank C++ project in VS 2019, then pasted the source lines, and set up the additional include path to include the protobuf installation directory/include, and additional lib path to the protobuf installation directory/lib. The addressbook.proto (from the example) was compiled, and the .cc file was included in this toy project as an additional file. The header file (.pb.h) was already referred to in the code, and all the include files, etc were found without any errors shown during compilation.
But, during the linking phase, it throws up 79 errors, most of which are apparently some missing library. It also shows up 163 Warnings. Some of the initial errors are reproduced here.
''' Error LNK2001 unresolved external symbol "private: unsigned char * __cdecl google::protobuf::io::EpsCopyOutputStream::WriteStringMaybeAliasedOutline(unsigned int,class std::basic_string<char,struct std::char_traits,class std::allocator > const &,unsigned char *)" (?WriteStringMaybeAliasedOutline@EpsCopyOutputStream@io@protobuf@google@@AEAAPEAEIAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAE@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
Error LNK2001 unresolved external symbol "private: unsigned char * __cdecl google::protobuf::io::EpsCopyOutputStream::EnsureSpaceFallback(unsigned char *)" (?EnsureSpaceFallback@EpsCopyOutputStream@io@protobuf@google@@AEAAPEAEPEAE@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
Error LNK2001 unresolved external symbol "void __cdecl google::protobuf::internal::InitSCCImpl(struct google::protobuf::internal::SCCInfoBase *)" (?InitSCCImpl@internal@protobuf@google@@YAXPEAUSCCInfoBase@123@@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
Error LNK2001 unresolved external symbol "void __cdecl google::protobuf::internal::VerifyVersion(int,int,char const *)" (?VerifyVersion@internal@protobuf@google@@YAXHHPEBD@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
Error LNK2001 unresolved external symbol "void __cdecl google::protobuf::internal::AssignDescriptors(struct google::protobuf::internal::DescriptorTable const *,bool)" (?AssignDescriptors@internal@protobuf@google@@YAXPEBUDescriptorTable@123@_N@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
Error LNK2001 unresolved external symbol "public: void __cdecl google::protobuf::internal::LogFinisher::operator=(class google::protobuf::internal::LogMessage &)" (??4LogFinisher@internal@protobuf@google@@QEAAXAEAVLogMessage@123@@Z) example_proto C:\Users\quasa\source\repos\example_proto\addressbook.pb.obj 1
'''
Very clearly, some library seems to be missing or not getting linked properly. However, 3 libraries seem to be present in the directory specified for additional libraries. I am obviously absolutely new to protobuf. Any advice is welcome.
Thanks
Upvotes: 1
Views: 1862
Reputation: 3076
Libraries are missing, because you have only specified libdirs. Have you actually linked required libraries? Because specifying libdirs (-L for gcc) is only a convenience so you can use -lmylibname
and not specify full path (check bottom of this article to see the difference).
So, in terms of g++ instructions, assuming main.o
needs to be linked with libyour.a
and the lib is in /lib directory, you've done the following:
g++ main.o -L/lib
You can clearly see that the library is not being linked. What you have to do instead:
g++ main.o -L/lib -lyour
(lib is being appended by the linker).
As you noticed in the comments yourself, considering you're using VS, there is a Additional Dependencies switch which you should configure.
Upvotes: 1