Project

General

Profile

Actions

Bug #17788

closed

ruby 3.0.0 - compiling c++ extension on alpine fails

Added by memel (Maia Engeli) 4 months ago. Updated 16 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux-musl]
[ruby-core:103323]

Description

Compiling gem with C++ extension fails on alpine 3xx with Ruby 3.0.0 and Ruby 3.0.1
(does not fail on Ubuntu 18 ¯\(ツ)/¯)

Error:

compiling testgem.cc
In file included from /root/.rbenv/versions/3.0.0/include/ruby-3.0.0/ruby/ruby.h:39,
                 from /root/.rbenv/versions/3.0.0/include/ruby-3.0.0/ruby.h:38,
                 from testgem.cc:2:
/root/.rbenv/versions/3.0.0/include/ruby-3.0.0/ruby/internal/memory.h:275:16: error: conflicting declaration of 'void* ruby_nonempty_memcpy(void*, const void*, size_t)' with 'C' linkage
  275 | #define memcpy ruby_nonempty_memcpy
      |                ^~~~~~~~~~~~~~~~~~~~
/root/.rbenv/versions/3.0.0/include/ruby-3.0.0/ruby/internal/memory.h:265:1: note: previous declaration with 'C++' linkage
  265 | ruby_nonempty_memcpy(void *dest, const void *src, size_t n)
      | ^~~~~~~~~~~~~~~~~~~~

Code for reproduction:

extconf.rb

require 'mkmf'
create_makefile 'testgem'

testgem.cc

#include <stdio.h>
#include <ruby.h>
#include <iostream>

VALUE says(VALUE _self, VALUE str) {
    Check_Type(str, T_STRING);
    puts(StringValueCStr(str));
    return Qnil;
}

void Init_testgem() {
    VALUE mod = rb_define_module("Simon");
    const int num_args = 1;
    std::cout << "*** testgem initialized ***" << std::endl;
    rb_define_module_function(mod, "says", says, num_args);
}

Files

testgem.cc (394 Bytes) testgem.cc memel (Maia Engeli), 04/08/2021 11:02 PM
extconf.rb (41 Bytes) extconf.rb memel (Maia Engeli), 04/08/2021 11:02 PM
ruby-ruby_nonempty_memcpy-musl-cxx.patch (370 Bytes) ruby-ruby_nonempty_memcpy-musl-cxx.patch xtkoba (Tee KOBAYASHI), 04/09/2021 12:08 AM

Updated by xtkoba (Tee KOBAYASHI) 4 months ago

Repro (named bug17788.cc):

#include <sys/types.h>

//extern "C" {
void *
ruby_nonempty_memcpy(void *dest, const void *src, size_t n)
{
  return dest;
}
//}

#undef memcpy
#define memcpy ruby_nonempty_memcpy

#include <iostream>
$ x86_64-unknown-linux-musl-g++ -c bug17788.cc
bug17788.cc:13:16: error: conflicting declaration of 'void* ruby_nonempty_memcpy(void*, const void*, size_t)' with 'C' linkage
   13 | #define memcpy ruby_nonempty_memcpy
      |                ^~~~~~~~~~~~~~~~~~~~
bug17788.cc:6:1: note: previous declaration with 'C++' linkage
    6 | ruby_nonempty_memcpy(void *dest, const void *src, size_t n)
      | ^~~~~~~~~~~~~~~~~~~~

A patch is attached for a workaround which wraps up the definition of ruby_nonempty_memcpy with extern "C" { ... }.

Updated by shyouhei (Shyouhei Urabe) 4 months ago

Good catch! Patch LGTM.

Actions #4

Updated by xtkoba (Tee KOBAYASHI) 16 days ago

  • Status changed from Open to Closed

Applied in changeset git|29f6f79e7396018962eb25c5f5e409f5fe28a73b.


Get ruby_nonempty_memcpy to have C linkage

Fixes [Bug #17788]

Actions

Also available in: Atom PDF