问题
Here's a question where Google hasn't been very helpful thus far:
I'm installing a RubyGem on Linux Mint that uses native extension, so it's trying to compile them on my machine. As often happens, it returns an error stating that it doesn't have all the tools on the machine necessary to build the extension:
Building native extensions. This could take a while...
ERROR: Error installing sas-helper:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for expat.h... yes
checking for XML_ParserCreate() in -lexpat... yes
checking for XML_SetNotStandaloneHandler()... yes
checking for XML_SetParamEntityParsing()... yes
checking for XML_SetDoctypeDeclHandler()... yes
checking for XML_ParserReset()... yes
checking for XML_SetSkippedEntityHandler()... yes
checking for XML_GetFeatureList()... yes
checking for XML_UseForeignDTD()... yes
checking for XML_GetIdAttributeIndex()... yes
checking for ntohl() in -lsocket... no
creating Makefile
make
compiling xmlparser.c
xmlparser.c: In function ‘XMLParser_mark’:
xmlparser.c:185:16: warning: variable ‘parent’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘iterExternalEntityRefHandler’:
xmlparser.c:372:9: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘myExternalEntityRefHandler’:
xmlparser.c:832:9: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘myStartCdataSectionHandler’:
xmlparser.c:860:14: warning: variable ‘parser’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘myEndCdataSectionHandler’:
xmlparser.c:868:14: warning: variable ‘parser’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘myNotStandaloneHandler’:
xmlparser.c:898:14: warning: variable ‘parser’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘myEndDoctypeDeclHandler’:
xmlparser.c:939:14: warning: variable ‘parser’ set but not used [-Wunused-but-set-variable]
xmlparser.c: In function ‘XMLParser_parse’:
xmlparser.c:1783:2: error: format not a string literal and no format arguments [-Werror=format-security]
xmlparser.c:1832:5: error: format not a string literal and no format arguments [-Werror=format-security]
cc1: some warnings being treated as errors
make: *** [xmlparser.o] Error 1
I've looked on Google, and haven't found much of anything that looks relevant to this situation. It appears that I'm missing this ntohl() function, can anyone tell me in which Debian package I can find this function?
回答1:
After some digging, I've found a solution!
You have to setup proper compiler flag: https://github.com/sparklemotion/nokogiri/issues/680#issuecomment-5830358
gem install xmlparser -- --with-cflags="-Wformat-security"
root@c6d50bebf05f:/var/lib/gems/2.0.0/gems# gem install xmlparser -- --with-cflags="-Wformat-security"
Building native extensions with: '--with-cflags=-Wformat-security'
This could take a while...
Successfully installed xmlparser-0.7.2.1
Parsing documentation for xmlparser-0.7.2.1
unable to convert "\xA0" from ASCII-8BIT to UTF-8 for /var/lib/gems/2.0.0/extensions/x86_64-linux/2.0.0/xmlparser-0.7.2.1/xmlparser.so, skipping
unable to convert "\xCD" from ASCII-8BIT to UTF-8 for README.ja, skipping
unable to convert "\xC0" from ASCII-8BIT to UTF-8 for ext/xmlparser.o, skipping
unable to convert "\xA0" from ASCII-8BIT to UTF-8 for ext/xmlparser.so, skipping
unable to convert "\xA0" from ASCII-8BIT to UTF-8 for lib/xmlparser.so, skipping
Installing ri documentation for xmlparser-0.7.2.1
1 gem installed
回答2:
I guess the package is happycoders-libsocket: http://www.happycoders.org/software/libsocket.php
回答3:
same issue as on Problems installing Nokogiri (1.5.2) on Ubuntu 12.10, quoting https://stackoverflow.com/users/65190/mike-dalessio:
Ubuntu 12.10 adopts Debian's hardening wrapper, which includes a set of default flags for GCC that cause this compilation error. We've worked around this in Nokogiri 1.5.4 and higher, so you'll need to either upgrade or find your own workaround.
See here for information on Debian hardening. http://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_FORMAT_.28gcc.2BAC8-g.2B-.2B--Wformat-Wformat-security_-Werror.3Dformat-security.29
See here for details on the solution used by Team Nokogiri. https://github.com/sparklemotion/nokogiri/issues/680
... just copying the information here so the next guy coming along can stop the digging :)
来源:https://stackoverflow.com/questions/16929004/rubygem-native-extension-cant-find-ntohl-in-lsocket