alpinelinux / docker-alpine

Official Alpine Linux Docker image. Win at minimalism!
MIT License
1.04k stars 261 forks source link

protobuf-dev issues on 3.19 #362

Open KiprasR opened 6 months ago

KiprasR commented 6 months ago

Hello.

profobuf-dev fails to run properly on arm64v8/alpine:latest (i.e., 3.19 at the moment). The code works well with the previous version (3.18).

I'm adding a MWE that runs through the same build steps as my server program (which explains the excessive compiler flags).

Dockerfile:

# Use ARMv8 Alpine image
FROM arm64v8/alpine:latest AS builder

# Install all necessary packages
RUN apk update
RUN apk add --no-cache g++
RUN apk add --no-cache protobuf
RUN apk add --no-cache protobuf-dev

# Create a workding directory
ADD . /app
WORKDIR /app

# Copy source code into container
COPY . /app

# Build libraries and protobuf headers
RUN protoc --cpp_out=. example.proto

# Build web-based tester
RUN g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static

# Use ARMv8 Alpine image
FROM arm64v8/alpine:latest AS release

ADD . /app
WORKDIR /app

COPY --from=builder /app .

# Run server
CMD ["./my_program"]

Protocol buffer:

syntax = "proto3";

message Person {
  string name = 1;
  int32 id = 2;
  string email = 3;
}

C++ main:

#include <iostream>
#include <fstream>
#include "example.pb.h"

int main() {
  Person person;
  person.set_name("John Doe");
  person.set_id(123);
  person.set_email("john@example.com");

  // Serialize the message to a file
  std::ofstream output("person.pb", std::ios::binary);
  person.SerializeToOstream(&output);
  output.close();

  // Deserialize the message from the file
  Person new_person;
  std::ifstream input("person.pb", std::ios::binary);
  new_person.ParseFromIstream(&input);

  // Display the deserialized message
  std::cout << "Name: " << new_person.name() << std::endl;
  std::cout << "ID: " << new_person.id() << std::endl;
  std::cout << "Email: " << new_person.email() << std::endl;

  return 0;
}

The image is built using sudo docker buildx build --platform linux/arm64/v8 -t alpine-test . --load

As mentioned earlier, everything builds just fine with arm64v8/alpine:3.18 If arm64v8/alpine:latest is used, a library linkage error is generated:

 => ERROR [builder 10/10] RUN g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static                                                                                                                                       45.5s
------
 > [builder 10/10] RUN g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static:
45.23 /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lprotobuf: No such file or directory
45.43 collect2: error: ld returned 1 exit status
------
Dockerfile:21
--------------------
  19 |
  20 |     # Build tester
  21 | >>> RUN g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static
  22 |
  23 |     # Use ARMv8 Alpine image
--------------------
ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static" did not complete successfully: exit code: 1

I'm getting the same cannot find -lprotobuf: No such file or directory error when building my server code as well.

KiprasR commented 6 months ago

Just to be clear, if we compile without all the excess flags:

RUN g++ main.cpp example.pb.cc -o my_program -lprotobuf

on v3.19 we end up with the following error:

 => ERROR [builder 10/10] RUN g++ main.cpp example.pb.cc -o my_program -lprotobuf                                                                                                                                                                                   42.3s
------
 > [builder 10/10] RUN g++ main.cpp example.pb.cc -o my_program -lprotobuf:
42.28 /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /tmp/cckdmgNg.o: undefined reference to symbol '_ZN4absl12lts_2023080212log_internal17MakeCheckOpStringIPKvS4_EEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_T0_PKc'
42.28 /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../lib/libabsl_log_internal_check_op.so.2308.0.0: error adding symbols: DSO missing from command line
42.29 collect2: error: ld returned 1 exit status
------
Dockerfile:23
--------------------
  21 |     # Build tester
  22 |     #RUN g++ -std=c++17 -Wall main.cpp example.pb.cc -o my_program -lprotobuf -ldl -Wno-psabi -O3 -static
  23 | >>> RUN g++ main.cpp example.pb.cc -o my_program -lprotobuf
  24 |
  25 |     # Use ARMv8 Alpine image
--------------------
ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c g++ main.cpp example.pb.cc -o my_program -lprotobuf" did not complete successfully: exit code: 1

The image builds just fine on 3.18.