1

I am trying to create an executable from object files. Here are the commands that I have used -

g++ -Wall -O3 -std=c++0x -march=native -fopenmp -pthread -I/usr/local/include -DUSESSE -DUSEOMP -c -o timer.o timer.cpp
g++  model.pb.cc -Wall -O3 -std=c++0x -march=native -fopenmp -pthread -I/usr/local/include -DUSESSE -DUSEOMP  `pkg-config --cflags --libs protobuf` -c -o ffm-model.o
g++ -c ffm.cpp -Wall -O3 -std=c++0x -march=native -fopenmp -pthread -I/usr/local/include -DUSESSE -DUSEOMP -pthread -L/usr/local/lib -lprotobuf -lpthread -I. -o ffm.o 
g++ -Wall -O3 -std=c++0x -march=native -fopenmp -pthread -I/usr/local/include -DUSESSE -DUSEOMP -pthread -I/usr/local/include  -pthread -L/usr/local/lib -lprotobuf -lpthread -o ffm-train ffm-train.cpp ffm.o timer.o ffm-model.o

But I am getting errors -

ffm.o: In function ffm::ffm_save_model(ffm::ffm_model&, std::string)': ffm.cpp:(.text+0x38b9): undefined reference to google::protobuf::Message::SerializeToOstream(std::ostream*) const' ffm.o: In function google::protobuf::RepeatedField<int>::Reserve(int)': ffm.cpp:(.text._ZN6google8protobuf13RepeatedFieldIiE7ReserveEi[_ZN6google8protobuf13RepeatedFieldIiE7ReserveEi]+0x67): undefined reference to google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)' ffm.cpp:(.text._ZN6google8protobuf13RepeatedFieldIiE7ReserveEi[_ZN6google8protobuf13RepeatedFieldIiE7ReserveEi]+0xfa): undefined reference to google::protobuf::Arena::OnArenaAllocation(std::type_info const*, unsigned long) const' ffm-model.o: In function protobuf_model_2eproto::InitDefaultsFFMmodelImpl()': model.pb.cc:(.text+0x1d): undefined reference to google::protobuf::internal::VerifyVersion(int, int, char const*)' model.pb.cc:(.text+0x22): undefined reference to google::protobuf::internal::InitProtobufDefaults()' model.pb.cc:(.text+0x57): undefined reference to google::protobuf::internal::OnShutdownDestroyMessage(void const*)' ffm-model.o: In function protobuf_model_2eproto::protobuf_AssignDescriptors()': model.pb.cc:(.text+0x107): undefined reference to google::protobuf::internal::AssignDescriptors(std::string const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)' ffm-model.o: In function protobuf_model_2eproto::protobuf_RegisterTypes(std::string const&)': model.pb.cc:(.text+0x188): undefined reference to google::protobuf::internal::RegisterAllTypes(google::protobuf::Metadata const*, int)' ffm-model.o: In function protobuf_model_2eproto::AddDescriptorsImpl()': model.pb.cc:(.text+0x1a2): undefined reference to google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int)' model.pb.cc:(.text+0x1b1): undefined reference to google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void ()(std::string const&))' ffm-model.o: In function FFMmodel::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)': model.pb.cc:(.text+0x7a6): undefined reference to google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)' model.pb.cc:(.text+0x9db): undefined reference to google::protobuf::internal::WireFormat::SkipField(google::protobuf::io::CodedInputStream*, unsigned int, google::protobuf::UnknownFieldSet*)' ffm-model.o: In function FFMmodel::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream) const': model.pb.cc:(.text+0xa40): undefined reference to google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xa71): undefined reference to google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xaa2): undefined reference to google::protobuf::internal::WireFormatLite::WriteInt32(int, int, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xad1): undefined reference to google::protobuf::internal::WireFormatLite::WriteBool(int, bool, google::protobuf::io::CodedOutputStream*)' model.pb.cc:(.text+0xc02): undefined reference to google::protobuf::internal::WireFormat::SerializeUnknownFields(google::protobuf::UnknownFieldSet const&, google::protobuf::io::CodedOutputStream*)' ffm-model.o: In functionFFMmodel::InternalSerializeWithCachedSizesToArray(bool, unsigned char*) const': model.pb.cc:(.text+0xe01): undefined reference to google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(google::protobuf::UnknownFieldSet const&, unsigned char*)' ffm-model.o: In function FFMmodel::ByteSizeLong() const': model.pb.cc:(.text+0xec5): undefined reference to google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(google::protobuf::UnknownFieldSet const&)' model.pb.cc:(.text+0xed9): undefined reference to google::protobuf::internal::WireFormatLite::Int32Size(google::protobuf::RepeatedField const&)' ffm-model.o: In function FFMmodel::MergeFrom(google::protobuf::Message const&)': model.pb.cc:(.text+0x101f): undefined reference to google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)' model.pb.cc:(.text+0x1035): undefined reference to google::protobuf::internal::LogMessage::operator<<(char const*)' model.pb.cc:(.text+0x104d): undefined reference to google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)' model.pb.cc:(.text+0x1061): undefined reference to google::protobuf::internal::LogMessage::~LogMessage()' model.pb.cc:(.text+0x108e): undefined reference to google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)' model.pb.cc:(.text+0x10bc): undefined reference to `google::protobuf::internal::LogMessage::~LogMessage()'

Any idea what I am doing wrong?

yashdosi
  • 1,186
  • 1
  • 18
  • 40
  • 1
    [Your linkage consumes libraries before the object files that refer to them](https://stackoverflow.com/a/43305704/1362568) – Mike Kinghan Nov 14 '17 at 19:21

0 Answers0