fjg / zipruby

Other
1 stars 13 forks source link

mkstemp.c:69:8: error: implicit declaration of function 'getpid' is invalid in C99 [-Werror,-Wimplicit-function-declaration] #5

Open vitscurtu opened 4 years ago

vitscurtu commented 4 years ago

Hi all. I'm trying to install zipruby via gem (on mac),

$ gem install zipruby -v 0.3.6

but I get the following error

Building native extensions. This could take a while...
ERROR:  Error installing zipruby:
    ERROR: Failed to build gem native extension.

    current directory: /Users/USER/.rvm/gems/ruby-2.5.5@go/gems/zipruby-0.3.6/ext
/Users/USER/.rvm/rubies/ruby-2.5.5/bin/ruby -I /Users/USER/.rvm/rubies/ruby-2.5.5/lib/ruby/site_ruby/2.5.0 -r ./siteconf20200924-5575-jr6479.rb extconf.rb
checking for zlib.h... yes
checking for -lz... yes
checking for fseeko()... yes
checking for ftello()... yes
checking for mkstemp()... yes
creating Makefile

current directory: /Users/USER/.rvm/gems/ruby-2.5.5@go/gems/zipruby-0.3.6/ext
make "DESTDIR=" clean

current directory: /Users/USER/.rvm/gems/ruby-2.5.5@go/gems/zipruby-0.3.6/ext
make "DESTDIR="
compiling mkstemp.c
mkstemp.c:69:8: error: implicit declaration of function 'getpid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        pid = getpid();
              ^
1 error generated.
make: *** [mkstemp.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/USER/.rvm/gems/ruby-2.5.5@go/gems/zipruby-0.3.6 for inspection.
Results logged to /Users/USER/.rvm/gems/ruby-2.5.5@go/extensions/x86_64-darwin-19/2.5.0/zipruby-0.3.6/gem_make.out

Tried fixing by including unistd.h in mkstemp.c, which lets me compile the code, but I'm not sure it's the right way.

Appreciate your help!

sighmon commented 4 years ago

Try: bundle config build.zipruby --with-cflags="-Wno-error=implicit-function-declaration"

I found that when fixing my thin install: https://github.com/macournoyer/thin/issues/365#issuecomment-696039939

veronvynguyen commented 3 years ago

Try: bundle config build.zipruby --with-cflags="-Wno-error=implicit-function-declaration"

I found that when fixing my thin install: macournoyer/thin#365 (comment)

Interesting, this command doesn't appear to be working for me, I ran it before running gem install zipruby -v '0.3.6'

ohboyd commented 3 years ago

I was able to solve a very similar case thanks to this ticket and a little more information from this stackoverflow post.

I'm using rbenv instead of rvm, and here's my error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/zipruby-0.3.6/ext
/Users/mikeboyd/.rbenv/versions/2.6.8/bin/ruby -I /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/2.6.0 -r ./siteconf20210812-27664-1wh21cw.rb extconf.rb -v\ 0.3.6\
--with-cflags\=-Wno-error\=implicit-function-declaration
checking for zlib.h... yes
checking for -lz... yes
checking for fseeko()... yes
checking for ftello()... yes
checking for mkstemp()... yes
creating Makefile

current directory: /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/zipruby-0.3.6/ext
make "DESTDIR=" clean

current directory: /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/zipruby-0.3.6/ext
make "DESTDIR="
compiling mkstemp.c
mkstemp.c:69:8: error: implicit declaration of function 'getpid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        pid = getpid();
              ^
1 error generated.
make: *** [mkstemp.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/zipruby-0.3.6 for inspection.
Results logged to /Users/mikeboyd/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-20/2.6.0/zipruby-0.3.6/gem_make.out

An error occurred while installing zipruby (0.3.6), and Bundler cannot continue.
Make sure that `gem install zipruby -v '0.3.6' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  zipruby

And here's my solution:

gem install zipruby -v '0.3.6' -- --with-cflags="-Wno-error=implicit-function-declaration"
sighmon commented 6 months ago

Not sure how much this is going to break things, but with Ruby 3.3.1 I can install with:

gem install zipruby -- --with-cflags="-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-function-pointer-types"