Forum: Ruby Building a C extension

1b7bd279fbd01e79d6da8c60e5f7c816?d=identicon&s=25 Florian Kasper (Guest)
on 2014-07-02 16:10
(Received via mailing list)
Hi,

After reading the discussion about "the death of Mailing lists", I
thought it would be good to post this question directly here:



I have a gem, I want to build the C extensions for. The gem source is
located here: https://github.com/nirnanaaa/cracklib .

If I build the source now on my mac (Mavericks) all the headers are
found and the gem gets built. All test cases pass correctly

.

Building the gem on Travis results in an error:



...

/home/travis/.rvm/rubies/ruby-2.1.1/bin/ruby -I.
../../../../ext/cracklib/extconf.rb

checking for sys/types.h... *** ../../../../ext/cracklib/extconf.rb
failed ***

Could not create Makefile due to some reason, probably lack of necessary

libraries and/or headers.  Check the mkmf.log file for more details.
 You may

need configuration options.

Provided configuration options:

  --with-opt-dir

  --without-opt-dir

  --with-opt-include

  --without-opt-include=${opt-dir}/include

  --with-opt-lib

  --without-opt-lib=${opt-dir}/lib

  --with-make-prog

  --without-make-prog

  --srcdir=../../../../ext/cracklib

  --curdir

  --ruby=/home/travis/.rvm/rubies/ruby-2.1.1/bin/ruby

/home/travis/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:456:in
`try_do': The compiler failed to generate an executable file.
(RuntimeError)

You have to install development tools first.

...





However the packages  "build-essential gcc automake" got installed on
the before_install step of travis' config

Maybe this is related to changing the HEADER_DIRS and LIB_DIRS in the
extconf.rb ?



Hope someone could help.

Thanks,

Flo
F6a8f6a0c94010f7b6ab011d59e9a906?d=identicon&s=25 Eric MSP Veith (Guest)
on 2014-07-02 17:09
(Received via mailing list)
Attachment: signature.asc (836 Bytes)
Hi Flo,

On Wednesday 02 July 2014 16:10:10, Florian Kasper <mosny@zyg.li> wrote:
> However the packages  "build-essential gcc automake" got installed on the
> before_install step of travis' config
>
> Maybe this is related to changing the HEADER_DIRS and LIB_DIRS in the
> extconf.rb ?

build-essential pulls in libc6-dev, which contains
/usr/include/sys/types.h.
If that's the culprit, the include paths are wrong.

Could you post the actual compiler command line? It should be in
mkmf.log.

HTH

      --- Eric
1b7bd279fbd01e79d6da8c60e5f7c816?d=identicon&s=25 Florian Kasper (Guest)
on 2014-07-03 13:17
(Received via mailing list)
Hi Eric,

thanks for helping me. I completely forgot about mkmf.log . Here is the
content of this log:

$ find . -type f -name mkmf.log|xargs cat
"gcc -o conftest 
  -I/home/travis/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/x86_64-linux 
  -I/home/travis/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/backward 
  -I/home/travis/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1 
  -I../../../../ext/cracklib     
  -O3 
  -ggdb 
  -Wall 
  -Wextra 
  -Wno-unused-parameter 
  -Wno-parentheses 
  -Wno-long-long 
  -Wno-missing-field-initializers 
  -Wpointer-arith 
  -Wwrite-strings 
  -Wdeclaration-after-statement 
  -Wimplicit-function-declaration  
  -fPIC conftest.c  
  -L. 
  -L/home/travis/.rvm/rubies/ruby-1.9.3-p545/lib 
  -Wl,-R/home/travis/.rvm/rubies/ruby-1.9.3-p545/lib 
  -L.  
  -rdynamic 
  -Wl,-export-dynamic 
  -lcrack     
  -Wl,-R -Wl,/home/travis/.rvm/rubies/ruby-1.9.3-p545/lib 
  -L/home/travis/.rvm/rubies/ruby-1.9.3-p545/lib 
  -lruby  
  -lpthread 
  -lrt 
  -ldl 
  -lcrypt 
  -lm   
  -lc"
/usr/bin/ld: cannot find -lcrack
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

I formatted the output to be more readable. As you already guessed the
linker include option for cracklib under $GEMROOT/vendor/cracklib/lib is
missing. 

Adding the HEADER_DIRS and LIB_DIRS directly to the LDFLAGS resulted in
exactly the same error:

"gcc 
  -o conftest 
  -I/home/travis/.rvm/rubies/ruby-2.0.0-p451/include/ruby-2.0.0/x86_64-linux 
  -I/home/travis/.rvm/rubies/ruby-2.0.0-p451/include/ruby-2.0.0/ruby/backward 
  -I/home/travis/.rvm/rubies/ruby-2.0.0-p451/include/ruby-2.0.0 
  -I../../../../ext/cracklib 
  -I/home/travis/build/nirnanaaa/cracklib/vendor/cracklib/lib 
  -I/opt/local/include 
  -I/usr/local/include 
  -I/home/travis/.rvm/rubies/ruby-2.0.0-p451/include 
  -I/usr/include 
  -I/include     
  -O3 
  -fno-fast-math 
  -ggdb3 
  -Wall 
  -Wextra 
  -Wno-unused-parameter 
  -Wno-parentheses 
  -Wno-long-long 
  -Wno-missing-field-initializers 
  -Wunused-variable 
  -Wpointer-arith 
  -Wwrite-strings 
  -Wdeclaration-after-statement 
  -Wimplicit-function-declaration  
  -fPIC conftest.c  
  -L. 
  -L/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib -Wl,-R/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib 
  -L/home/travis/build/nirnanaaa/cracklib/vendor/cracklib/lib -Wl,-R/home/travis/build/nirnanaaa/cracklib/vendor/cracklib/lib 
  -L/usr/local/lib -Wl,-R/usr/local/lib 
  -L/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib
-Wl,-R/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib 
  -L/usr/lib -Wl,-R/usr/lib 
  -L/lib -Wl,-R/lib 
  -L. 
  -fstack-protector 
  -rdynamic 
  -Wl,
  -export-dynamic 
  -lcrack 
  -I /home/travis/build/nirnanaaa/cracklib/vendor/cracklib/lib 
  -I /opt/local/include 
  -I /usr/local/include 
  -I /home/travis/.rvm/rubies/ruby-2.0.0-p451/include 
  -I /usr/include 
  -I /include 
  -L /home/travis/build/nirnanaaa/cracklib/vendor/cracklib/lib 
  -L /usr/local/lib 
  -L /home/travis/.rvm/rubies/ruby-2.0.0-p451/lib 
  -L /usr/lib 
  -L /lib     '-Wl,-rpath,/../lib' -Wl,-R
-Wl,/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib
-L/home/travis/.rvm/rubies/ruby-2.0.0-p451/lib -lruby  -lpthread -lrt
-ldl -lcrypt -lm   -lc"
/usr/bin/ld: cannot find -lcrack
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */


---
Flo
On July 2, 2014 at 5:10:03 PM, Eric MSP Veith (eveith@wwweb-library.net)
wrote:

Hi Flo,

On Wednesday 02 July 2014 16:10:10, Florian Kasper <mosny@zyg.li> wrote:
> However the packages "build-essential gcc automake" got installed on the
> before_install step of travis' config
>
> Maybe this is related to changing the HEADER_DIRS and LIB_DIRS in the
> extconf.rb ?

build-essential pulls in libc6-dev, which contains
/usr/include/sys/types.h.
If that's the culprit, the include paths are wrong.

Could you post the actual compiler command line? It should be in
mkmf.log.

HTH

--- Eric
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.