Nate K
Nate K

Reputation: 69

Unable to build C++ project w/ protobuf

I'm having trouble figuring out how to build a project with C++ protobufs. I'm on arm Mac and followed the instructions here to the T but keep on getting the error shown below when trying to build my project.

g++ -std=c++20 main.cpp test.pb.cc `pkg-config --cflags --libs protobuf`
Undefined symbols for architecture arm64:
  "google::protobuf::internal::InternalMetadata::~InternalMetadata()", referenced from:
      google::protobuf::MessageLite::~MessageLite() in test-a4504a.o
ld: symbol(s) not found for architecture arm64

https://github.com/protocolbuffers/protobuf/blob/main/src/README.md

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make -j$(nproc) # $(nproc) ensures it uses all cores for compilation
make check
sudo make install

See installed binaries / headers

ls -la /usr/local/include/google/protobuf/ | wc
      75     668    4693

ls /usr/local/lib | grep -i proto
libprotobuf-lite.31.dylib
libprotobuf-lite.a
libprotobuf-lite.dylib
libprotobuf-lite.la
libprotobuf.31.dylib
libprotobuf.a
libprotobuf.dylib
libprotobuf.la
libprotoc.31.dylib
libprotoc.a
libprotoc.dylib
libprotoc.la

protoc --version
libprotoc 3.20.1

Main

#include <iostream>

#include "test.pb.h"

int main() {
    std::cout << "Hello World" << std::endl;
    auto t = proto::TimeseriesPoint();
    std::cout << t.timestamp() << std::endl;
    return 0;
}

.proto

syntax = "proto3";

package proto;

message TimeseriesPoint {
  uint32 timestamp = 1;
  double value = 2;
}

Tips appreciated. I've tried removing the protobuf install and rebuilding from source multiple times to no luck.

Upvotes: 1

Views: 783

Answers (0)

Related Questions