Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grpc_example] Unrecognized command-line option '-ignore:4221' when building with MinGW #39275

Open
FeathBow opened this issue Jun 13, 2024 · 0 comments
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team.

Comments

@FeathBow
Copy link

Operating system

Windows 10 Enterprise

Compiler

MinGW g++ 13.2.0

Steps to reproduce the behavior

## Environment Information:

Operating System: Windows 10 Enterprise
C++ Standard: C++20
vcpkg Version: 2024-04-23
gRPC Version: Installed via vcpkg
Compiler: MinGW g++ 13.2.0

## Reproduction Steps:

Install gRPC using vcpkg.
Configure CMake with MinGW Makefiles.

D:\grpc_example\build>cmake -G "MinGW Makefiles" ..\ -DCMAKE_TOOLCHAIN_FILE=F:\vcpkg\script
s\buildsystems\vcpkg.cmake
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/mingw64-gcc-13/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/mingw64-gcc-13/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: F:/vcpkg/installed/x64-windows/lib/zlib.lib (found version "1.3.1")
-- Found Protobuf: F:/vcpkg/installed/x64-windows/tools/protobuf/protoc.exe (found version "3.21.12.0")
-- Found OpenSSL: F:/vcpkg/installed/x64-windows/debug/lib/libcrypto.lib (found version "3.3.0")
-- Found c-ares: F:/vcpkg/installed/x64-windows/share/c-ares/c-ares-config.cmake (found version "1.28.1")

-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found RE2 via CMake.
-- Configuring done (19.5s)
-- Generating done (0.1s)
-- Build files have been written to: D:/grpc_example/build
Execute cmake --build . to compile.

Failure logs

D:\grpc_example\build>cmake --build .
[ 12%] Building CXX object CMakeFiles/server.dir/src/server.cpp.obj
[ 25%] Building CXX object CMakeFiles/server.dir/proto/helloworld.grpc.pb.cc.obj
[ 37%] Building CXX object CMakeFiles/server.dir/proto/helloworld.pb.cc.obj
[ 50%] Linking CXX executable server.exe
c++.exe: error: unrecognized command-line option '-ignore:4221'
mingw32-make[2]: *** [CMakeFiles\server.dir\build.make:168: server.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/server.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2

Additional context

Project Structure and CMakeLists.txt

grpc_example/
|-- CMakeLists.txt
|-- build/
|-- proto/
|   |-- helloworld.grpc.pb.cc
|   |-- helloworld.grpc.pb.h
|   |-- helloworld.pb.cc
|   |-- helloworld.pb.h
|   `-- helloworld.proto
`-- src/
    |-- client.cpp
    |-- grpc_example.lnk
    `-- server.cpp

CMakeLists.txt content

cmake_minimum_required( VERSION 3.1 )
project( grpc_example )
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED )
add_executable( server src/server.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)
add_executable( client src/client.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)
target_link_libraries( server PRIVATE ws2_32 gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )
target_link_libraries( client PRIVATE ws2_32 gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )

server.cpp Content

/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <iostream>
#include <memory>
#include <string>

#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>
#include <grpcpp/ext/proto_server_reflection_plugin.h>

#ifdef BAZEL_BUILD
#include "../proto/helloworld.grpc.pb.h"
#else
#include "../proto/helloworld.grpc.pb.h"
#endif

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
using helloworld::Greeter;

// Logic and data behind the server's behavior.
class GreeterServiceImpl final : public Greeter::Service {
  Status SayHello(ServerContext* context, const HelloRequest* request,
                  HelloReply* reply) override {
    std::string prefix("Hello ");
    reply->set_message(prefix + request->name());
    return Status::OK;
  }
};

void RunServer() {
  std::string server_address("0.0.0.0:50051");
  GreeterServiceImpl service;

  grpc::EnableDefaultHealthCheckService(true);
  grpc::reflection::InitProtoReflectionServerBuilderPlugin();
  ServerBuilder builder;
  // Listen on the given address without any authentication mechanism.
  builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
  // Register "service" as the instance through which we'll communicate with
  // clients. In this case it corresponds to an *synchronous* service.
  builder.RegisterService(&service);
  // Finally assemble the server.
  std::unique_ptr<Server> server(builder.BuildAndStart());
  std::cout << "Server listening on " << server_address << std::endl;

  // Wait for the server to shutdown. Note that some other thread must be
  // responsible for shutting down the server for this call to ever return.
  server->Wait();
}

int main(int argc, char** argv) {
  RunServer();

  return 0;
}

client.cpp Content

/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <iostream>
#include <memory>
#include <string>

#include <grpcpp/grpcpp.h>

#ifdef BAZEL_BUILD
#include "../proto/helloworld.grpc.pb.h"
#else
#include "../proto/helloworld.grpc.pb.h"
#endif

using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
using helloworld::Greeter;

class GreeterClient {
 public:
  GreeterClient(std::shared_ptr<Channel> channel)
      : stub_(Greeter::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  std::string SayHello(const std::string& user) {
    // Data we are sending to the server.
    HelloRequest request;
    request.set_name(user);

    // Container for the data we expect from the server.
    HelloReply reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;

    // The actual RPC.
    Status status = stub_->SayHello(&context, request, &reply);

    // Act upon its status.
    if (status.ok()) {
      return reply.message();
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      return "RPC failed";
    }
  }

 private:
  std::unique_ptr<Greeter::Stub> stub_;
};

int main(int argc, char** argv) {
  // Instantiate the client. It requires a channel, out of which the actual RPCs
  // are created. This channel models a connection to an endpoint specified by
  // the argument "--target=" which is the only expected argument.
  // We indicate that the channel isn't authenticated (use of
  // InsecureChannelCredentials()).
  std::string target_str;
  std::string arg_str("--target");
  if (argc > 1) {
    std::string arg_val = argv[1];
    size_t start_pos = arg_val.find(arg_str);
    if (start_pos != std::string::npos) {
      start_pos += arg_str.size();
      if (arg_val[start_pos] == '=') {
        target_str = arg_val.substr(start_pos + 1);
      } else {
        std::cout << "The only correct argument syntax is --target=" << std::endl;
        return 0;
      }
    } else {
      std::cout << "The only acceptable argument is --target=" << std::endl;
      return 0;
    }
  } else {
    target_str = "192.168.3.22:50051";
  }
  GreeterClient greeter(grpc::CreateChannel(
      target_str, grpc::InsecureChannelCredentials()));
  std::string user("world");
  std::string reply = greeter.SayHello(user);
  std::cout << "Greeter received: " << reply << std::endl;

  return 0;
}

proto File Content

// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

proto Compilation Commands

protoc --proto_path=. --cpp_out=. helloworld.proto
protoc --proto_path=. --grpc_out=. --plugin=protoc-gen-grpc="F:\vcpkg\packages\grpc_x64-windows\tools\grpc\grpc_cpp_plugin.exe" helloworld.proto
@FeathBow FeathBow added the category:port-bug The issue is with a library, which is something the port should already support label Jun 13, 2024
@LilyWangLL LilyWangLL added category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. and removed category:port-bug The issue is with a library, which is something the port should already support labels Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team.
Projects
None yet
Development

No branches or pull requests

2 participants