Bug report: ruby-1.8.0p3 fails to compile under FreeBSD-4.7

B

Brian Candler

--7JfCtLOvnd9MIVvH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

gcc -fPIC -g -O2 -DDB_DBM_HSEARCH -DDBM_HDR="<db.h>" -I. -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0/ext/dbm -DHAVE_DB_H -DHAVE_SYS_CDEFS_H -DHAVE___DB_NDBM_OPEN -DHAVE___DB_NDBM_CLEARERR -c dbm.c
dbm.c:29: syntax error before `DBM'
dbm.c: In function `free_dbm':
dbm.c:49: structure has no member named `di_dbm'
dbm.c:49: structure has no member named `di_dbm'
dbm.c: In function `fdbm_close':
dbm.c:60: structure has no member named `di_dbm'
dbm.c:61: structure has no member named `di_dbm'
dbm.c:62: structure has no member named `di_dbm'
dbm.c: In function `fdbm_initialize':
dbm.c:82: `DBM' undeclared (first use in this function)
dbm.c:82: (Each undeclared identifier is reported only once
dbm.c:82: for each function it appears in.)
dbm.c:82: `dbm' undeclared (first use in this function)
dbm.c:83: syntax error before `struct'
dbm.c:87: `mode' undeclared (first use in this function)
dbm.c:113: `dbmp' undeclared (first use in this function)
<<< snip more similar errors >>>

On this box, DBM is defined in /usr/include/ndbm.h:

typedef DB DBM;

It in turn includes <db.h>, which defines DB and DBT.

Editing the ext/dbm/Makefile manually, so that it has -DDBM_HDR="<ndbm.h>",
allows the compile to continue.

ext/dbm/mkmf.log is attached.

Regards,

Brian.

--7JfCtLOvnd9MIVvH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mkmf.log"

have_library: checking for __db_ndbm_open() in -ldb...
gcc -o conftest -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 conftest.c -L/u/home/telinco/build/ruby/ruby-1.8.0 -L/usr/local/lib -rdynamic -lruby-static -ldb -lcrypt -lm -lc
checked program was:
/* begin */

int main() { return 0; }
int t() { __db_ndbm_open(); return 0; }
/* end */

have_header: checking for db.h...
gcc -E -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 -o conftest.i conftest.c
checked program was:
/* begin */
#include <db.h>
/* end */

have_header: checking for cdefs.h...
gcc -E -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 -DDB_DBM_HSEARCH -DDBM_HDR=<db.h> -o conftest.i conftest.c
conftest.c:1: cdefs.h: No such file or directory
checked program was:
/* begin */
#include <cdefs.h>
/* end */

have_header: checking for sys/cdefs.h...
gcc -E -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 -DDB_DBM_HSEARCH -DDBM_HDR=<db.h> -o conftest.i conftest.c
checked program was:
/* begin */
#include <sys/cdefs.h>
/* end */

have_func: checking for __db_ndbm_open()...
gcc -o conftest -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 -DDB_DBM_HSEARCH -DDBM_HDR=<db.h> conftest.c -L/u/home/telinco/build/ruby/ruby-1.8.0 -L/usr/local/lib -rdynamic -ldb -lruby-static -ldb -lcrypt -lm -lc
checked program was:
/* begin */

int main() { return 0; }
int t() { __db_ndbm_open(); return 0; }
/* end */

have_func: checking for __db_ndbm_clearerr()...
gcc -o conftest -I/u/home/telinco/build/ruby/ruby-1.8.0 -I/u/home/telinco/build/ruby/ruby-1.8.0 -g -O2 -DDB_DBM_HSEARCH -DDBM_HDR=<db.h> conftest.c -L/u/home/telinco/build/ruby/ruby-1.8.0 -L/usr/local/lib -rdynamic -ldb -lruby-static -ldb -lcrypt -lm -lc
checked program was:
/* begin */

int main() { return 0; }
int t() { __db_ndbm_clearerr(); return 0; }
/* end */


--7JfCtLOvnd9MIVvH--
 
N

nobu.nokada

Hi,

At Wed, 23 Jul 2003 02:52:44 +0900,
Brian said:
When I build under FreeBSD-4.7 (working around the dbm problem as outlined
before), and then install, libruby doesn't seem to get installed:

$ find /usr/local/lib/ruby/1.8 -name 'libruby*'
$

But it was installed when I build 1.6.8:

$ find /usr/local/lib/ruby/1.6 -name 'libruby*'
/usr/local/lib/ruby/1.6/i386-freebsd4.7/libruby.a
$

There should be libruby-static.a at /usr/local/lib.
 
N

nobu.nokada

Hi,

At Wed, 23 Jul 2003 00:20:39 +0900,
Brian said:
On this box, DBM is defined in /usr/include/ndbm.h:

typedef DB DBM;

It in turn includes <db.h>, which defines DB and DBT.

Editing the ext/dbm/Makefile manually, so that it has -DDBM_HDR="<ndbm.h>",
allows the compile to continue.

Does this patch work?


Index: lib/mkmf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.138
diff -u -2 -p -r1.138 mkmf.rb
--- lib/mkmf.rb 23 Jul 2003 05:19:22 -0000 1.138
+++ lib/mkmf.rb 23 Jul 2003 06:35:30 -0000
@@ -250,4 +250,58 @@ def cpp_include(header)
end

+def try_static_assert(expr, headers = nil, opt = "")
+ headers = cpp_include(headers)
+ try_compile(<<SRC, opt)
+#{COMMON_HEADERS}
+#{headers}
+int tmp[(#{expr}) ? 1 : -1];
+SRC
+end
+
+def try_constant(const, headers = nil, opt = "")
+ if true # CROSS_COMPILING
+ unless try_compile(<<"SRC", opt)
+#{COMMON_HEADERS}
+#{cpp_include(headers)}
+int tmp = #{const};
+SRC
+ return nil
+ end
+ if try_static_assert("#{const} < 0", headers, opt)
+ neg = true
+ const = "-(#{const})"
+ elsif try_static_assert("#{const} == 0", headers, opt)
+ return 0
+ end
+ upper = 1
+ until try_static_assert("#{const} < #{upper}", headers, opt)
+ lower = upper
+ upper <<= 1
+ end
+ return nil unless lower
+ until try_static_assert("#{const} == #{upper}", headers, opt)
+ if try_static_assert("#{const} > #{(upper+lower)/2}", headers, opt)
+ lower = (upper+lower)/2
+ else
+ upper = (upper+lower)/2
+ end
+ end
+ upper = -upper if neg
+ return upper
+ else
+ src = %{#{COMMON_HEADERS}
+#{cpp_include(headers)}
+#include <stdio.h>
+int main() {printf("%d\\n", (int)(#{const})); return 0;}
+}
+ if try_link0(src, opt)
+ xpopen("./conftest") do |f|
+ return Integer(f.gets)
+ end
+ end
+ end
+ nil
+end
+
def try_func(func, libs, headers = nil)
headers = cpp_include(headers)
@@ -443,4 +497,36 @@ SRC
end

+def have_type(type, header=nil, opt="")
+ checking_for type do
+ if try_compile(<<"SRC", opt) or try_compile(<<"SRC", opt)
+#{COMMON_HEADERS}
+#{cpp_include(header)}
+static #{type} t;
+SRC
+#{COMMON_HEADERS}
+#{cpp_include(header)}
+static #{type} *t;
+SRC
+ $defs.push(format("-DHAVE_TYPE_%s", type.upcase))
+ true
+ else
+ false
+ end
+ end
+end
+
+def check_sizeof(type, header=nil)
+ expr = "sizeof(#{type})"
+ m = "checking size of #{type}... "
+ message "%s", m
+ Logging::message "check_sizeof: %s--------------------\n", m
+ if size = try_constant(expr, header)
+ $defs.push(format("-DSIZEOF_%s", type.upcase))
+ end
+ message(a = size ? "#{size}\n" : "failed\n")
+ Logging::message "-------------------- %s\n", a
+ r
+end
+
def find_executable0(bin, path = nil)
path = (path || ENV['PATH']).split(File::pATH_SEPARATOR)
Index: ext/dbm/extconf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/dbm/extconf.rb,v
retrieving revision 1.15
diff -u -2 -p -r1.15 extconf.rb
--- ext/dbm/extconf.rb 7 Jul 2003 01:30:02 -0000 1.15
+++ ext/dbm/extconf.rb 23 Jul 2003 06:37:03 -0000
@@ -33,5 +33,5 @@ def db_check(db)
if have_library(db, db_prefix("dbm_open")) || have_func(db_prefix("dbm_open"))
for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"])
- if have_header(hdr.dup)
+ if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch)
$CFLAGS += " " + hsearch + '-DDBM_HDR="<'+hdr+'>"'
return true
 
B

Brian Candler

Does this patch work?

Yes: it happily compiles from start to end, and dbm.so is created. Many
thanks.

I wasn't aware of this module before, since it's not mentioned in the
Pickaxe. Very cool. I tested it by making a small dbm file in 1.6.8 and
reading it in 1.8.0p3, and it seems fine.

Incidentally, I note there is a method DBM#to_hash. This sets a precedent
for having Array#to_hash as discussed previously :)

Regards,

Brian.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Bug report: ruby-1.8.0p3 fails to compile under FreeBSD-4.7"

|Incidentally, I note there is a method DBM#to_hash. This sets a precedent
|for having Array#to_hash as discussed previously :)

"to_hash" is a method used by implicit conversion, like "to_str".

matz.
 
N

nobu.nokada

Hi,

At Wed, 23 Jul 2003 19:55:25 +0900,
Brian said:
Ah, there it is. But this now seems inconsistent. If you're going to put the
library in /usr/local/lib, surely ruby.h should be installed in
/usr/local/include?

Maybe, /usr/local/include/ruby-1.8? Or, as you mentioned,
multiple versions won't be possible to coexist.
I actually liked it as it was - since I'm just starting to play with 1.8.0,
having both versions in separate places makes it easy to link against one
versus the other. But in future this won't be possible.

--program-prefix, --program-suffix and --program-transform-name
can change the name.
Also - I don't get a .so. Is that a platform limitation, or a compile-time
option? Any reason not to build it by default?

libruby.so? Try configure with --enable-shared.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top