Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to build gem native extension. pg 1.2.3. Mac OS Ventura #496

Closed
Nerian opened this issue Feb 21, 2023 · 3 comments
Closed

Failed to build gem native extension. pg 1.2.3. Mac OS Ventura #496

Nerian opened this issue Feb 21, 2023 · 3 comments

Comments

@Nerian
Copy link

Nerian commented Feb 21, 2023

Hi,

I am trying to build the pg gem but I get an error.

$ ruby -v
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-darwin22]

$ uname -a
Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64
Mac OS Ventura 13.2.1

Using postgresql@15  / 15.2 installed via brew.

I have this on the .zshrc

export PATH="/usr/local/opt/postgresql@15/bin:$PATH"
export LDFLAGS="-L$(pg_config --libdir)"
export CPPFLAGS="$(pg_config --cppflags)"
export PKG_CONFIG_PATH="/usr/local/opt/postgresql@15/lib/pkgconfig"

Installing the gem:

$ gem install pg -v 1.2.3

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

    current directory: /Users/Nerian/.rvm/gems/ruby-3.2.1/gems/pg-1.2.3/ext
/Users/Nerian/.rvm/rubies/ruby-3.2.1/bin/ruby -I /Users/Nerian/.rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0 extconf.rb
checking for pg_config... yes
Using config values from /usr/local/opt/postgresql@15/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... yes
checking for PQresultMemorySize()... yes
checking for timegm()... yes
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile

current directory: /Users/Nerian/.rvm/gems/ruby-3.2.1/gems/pg-1.2.3/ext
make DESTDIR\= sitearchdir\=./.gem.20230221-38265-zp5zm3 sitelibdir\=./.gem.20230221-38265-zp5zm3 clean

current directory: /Users/Nerian/.rvm/gems/ruby-3.2.1/gems/pg-1.2.3/ext
make DESTDIR\= sitearchdir\=./.gem.20230221-38265-zp5zm3 sitelibdir\=./.gem.20230221-38265-zp5zm3
compiling gvl_wrappers.c
In file included from gvl_wrappers.c:6:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
2 warnings generated.
compiling pg.c
In file included from pg.c:49:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
2 warnings generated.
compiling pg_binary_decoder.c
In file included from pg_binary_decoder.c:8:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
2 warnings generated.
compiling pg_binary_encoder.c
In file included from pg_binary_encoder.c:7:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
2 warnings generated.
compiling pg_coder.c
In file included from pg_coder.c:6:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
pg_coder.c:216:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                      ^~~~~~~~~~~~~~~~~~~~
/Users/Nerian/.rvm/rubies/ruby-3.2.1/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN       RSTRING_LEN
                          ^
3 warnings generated.
compiling pg_connection.c
In file included from pg_connection.c:7:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
pg_connection.c:679:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return INT2NUM(atol(port));
               ~~~~~~~ ^~~~~~~~~~
3 warnings generated.
compiling pg_copy_coder.c
In file included from pg_copy_coder.c:6:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
pg_copy_coder.c:228:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/Nerian/.rvm/rubies/ruby-3.2.1/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN       RSTRING_LEN
                          ^
pg_copy_coder.c:534:23: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                input_len = end_ptr - start_ptr;
                          ~ ~~~~~~~~^~~~~~~~~~~
4 warnings generated.
compiling pg_errors.c
In file included from pg_errors.c:6:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
2 warnings generated.
compiling pg_record_coder.c
In file included from pg_record_coder.c:6:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
pg_record_coder.c:196:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/Nerian/.rvm/rubies/ruby-3.2.1/include/ruby-3.2.0/ruby/internal/core/rstring.h:52:27: note: expanded from macro 'RSTRING_LEN'
#define RSTRING_LEN       RSTRING_LEN
                          ^
3 warnings generated.
compiling pg_result.c
In file included from pg_result.c:7:
In file included from ./pg.h:61:
/usr/local/opt/postgresql@15/include/pg_config_manual.h:85:5: warning: 'SIZEOF_VOID_P' is not defined, evaluates to 0 [-Wundef]
#if SIZEOF_VOID_P >= 8
    ^
/usr/local/opt/postgresql@15/include/pg_config_manual.h:168:5: warning: 'HAVE_DECL_POSIX_FADVISE' is not defined, evaluates to 0 [-Wundef]
#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)
    ^
pg_result.c:1006:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return INT2NUM(n);
               ~~~~~~~ ^
pg_result.c:1590:58: error: use of undeclared identifier 'rb_cData'
        rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cData );
                                                                ^
3 warnings and 1 error generated.
make: *** [pg_result.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/Nerian/.rvm/gems/ruby-3.2.1/gems/pg-1.2.3 for inspection.
Results logged to /Users/Nerian/.rvm/gems/ruby-3.2.1/extensions/x86_64-darwin-22/3.2.0/pg-1.2.3/gem_make.out

Can't upgrade yet to version 1.4 due other dependency.

Can you point to me what else can I try?

Thanks.

@larskanis
Copy link
Collaborator

You could use a hack like this:

gem inst pg:1.2.3 -- --with-cflags=-Drb_cData=rb_cObject

But honesty you shouldn't use a pg version that is 3 years older than the ruby version you're using, but instead fix the dependency issue. Is there a reason that the dependency is locked to pg-1.2.3?

@larskanis
Copy link
Collaborator

I'll close the issue since the related issue with pg-1.3.0 to 1.4.5 is solved by #498 . The old pg-1.2.3 is still required by lsylvester/active_storage-postgresql#16 but I opened a PR to fix this - now that pg-1.4.6 is released: lsylvester/active_storage-postgresql#17

@Nerian
Copy link
Author

Nerian commented Mar 16, 2023

Thank you for your work 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants