Issue #18000 has been updated by jeremyevans0 (Jeremy Evans).

File rb_prefix_hack.diff added
File no-static-no-shared.diff added

While it is possible to compile with only the headers, that only works if you know what the headers should contain.  If you aren't sure what the headers contain, and you have to test, you really need to test both compiling and linking to be reasonably sure whether the headers support the function in question.  You can only do such testing if you have either the shared or static library available.

The issue here is how the mkmf `have_func` method works.  Currently, it writes a small C program and tries to compile and link it.  If it cannot do so correctly, it determines the function doesn't work.  You can work around this by only trying to compile and not link.  However, that breaks cases that will compile but won't link, or won't compile unless you link. Such cases exist in the openssl extension, at least in my environment.  Either I couldn't get Ruby to build with the changes, or the built Ruby wouldn't have a working openssl extension (needed for `gem install`).  I've attached my attempt at this in case you want to keep hacking to make it work.  I don't think the approach is feasible, though.

One possible hack that may work for this use case is if `have_func` is checking for a function that starts with `rb_`, assume it is already defined.  These calls are usually used to check that the Ruby version in use includes a function that wasn't defined in previous Ruby versions.  If you are running the latest Ruby version, all of these functions are probably defined.  This is obviously a hack we couldn't ship, though from my testing, it does allow `gem install stackprof`.  I've attached this hack as well.

I think the `tool/mkconfig.rb` changes in both patches should be committed.  These remove the `-lruby-static` from `LIBRUBYARG_STATIC`.  After all, there is no point trying to link to a library that you know you didn't install.  I've submitted a pull request for that: https://github.com/ruby/ruby/pull/4736

----------------------------------------
Bug #18000: have_library doesn't work when ruby is compiled with --disable-shared --disable-install-static-library
https://bugs.ruby-lang.org/issues/18000#change-93262

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Related [Feature #12845] 

If you compile ruby with `--disable-shared --disable-install-static-library`, then many C-extension won't compile anymore. For instance `RedCloth`

```ruby
# extconf.rb
require 'mkmf'
CONFIG['warnflags'].gsub!(/-Wshorten-64-to-32/, '') if CONFIG['warnflags']
$CFLAGS << ' -O0 -Wall ' if CONFIG['CC'] =~ /gcc/
dir_config("redcloth_scan")
have_library("c", "main")
create_makefile("redcloth_scan")
```

```
#mkmf.log 

"gcc -o conftest -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I. -I/usr/local/include    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -O0 -Wall  conftest.c  -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -L/usr/local/lib  -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby-static -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm
    -lm   -lc"
/usr/bin/ld: cannot find -lruby-static
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */
```

We'd like to use both flags, the first because it provide a small performance improvement, the second because `libruby-static.a` is enormous (up to 120MiB on debug builds).

@alanwu says it's theoretically possible to compile with just the headers.

---Files--------------------------------
no-static-no-shared.diff (2.55 KB)
rb_prefix_hack.diff (1.76 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>