ruby-pg
ruby-pg copied to clipboard
Big Sur Gem Install Issues
I can't get pg installed using the preferred method using homebrew. I'm using the postgres.app which is the only way I found to get postgres installed on this brand new box. This app has its own encapsulation with regards to psql, pg_config and other apps, config files, etc.
Big Sur on Mac Mini M1.
Yes, I've read the other posts about Big Sur, but they are much earlier than this post, which is mid-March. Different feedback as well. I can get this to work using the since-deleted homebrew installation of pg_config, but that's cheating. Here is the gem installation that I've tried.
~ ❯ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/12/bin/pg_config --with--with-libpq-dir=/opt/homebrew/opt/libpq
Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/12/bin/pg_config --with--with-libpq-dir=/opt/homebrew/opt/libpq'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/rich/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pg-1.2.3/ext
/Users/rich/.rbenv/versions/2.7.2/bin/ruby -I /Users/rich/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20210317-69773-cz32yu.rb extconf.rb --with-pg-config\=/Applications/Postgres.app/Contents/Versions/12/bin/pg_config --with--with-libpq-dir\=/opt/homebrew/opt/libpq
Using config values from /Applications/Postgres.app/Contents/Versions/12/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... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=.
--curdir
--ruby=/Users/rich/.rbenv/versions/2.7.2/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pq-dir
--without-pq-dir
--with-pq-include
--without-pq-include=${pq-dir}/include
--with-pq-lib
--without-pq-lib=${pq-dir}/lib
--with-pqlib
--without-pqlib
--with-libpq-dir
--without-libpq-dir
--with-libpq-include
--without-libpq-include=${libpq-dir}/include
--with-libpq-lib
--without-libpq-lib=${libpq-dir}/lib
--with-libpqlib
--without-libpqlib
--with-ms/libpq-dir
--without-ms/libpq-dir
--with-ms/libpq-include
--without-ms/libpq-include=${ms/libpq-dir}/include
--with-ms/libpq-lib
--without-ms/libpq-lib=${ms/libpq-dir}/lib
--with-ms/libpqlib
--without-ms/libpqlib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/rich/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/arm64-darwin-20/2.7.0/pg-1.2.3/mkmf.log
extconf failed, exit code 1
#############################################################
## mkmf.log:
<snip>
have_library: checking for PQconnectdb() in -lpq... -------------------- no
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -lpq "
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/12/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_PQconnectdb", referenced from:
_t in conftest-e19fd3.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
/* end */
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -lpq "
conftest.c:16:13: error: conflicting types for 'PQconnectdb'
extern void PQconnectdb();
^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:16: note: previous declaration is here
extern PGconn *PQconnectdb(const char *conninfo);
^
conftest.c:17:27: error: too few arguments to function call, single argument 'conninfo' was not specified
int t(void) { PQconnectdb(); return 0; }
~~~~~~~~~~~ ^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:1: note: 'PQconnectdb' declared here
extern PGconn *PQconnectdb(const char *conninfo);
^
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: extern void PQconnectdb();
17: int t(void) { PQconnectdb(); return 0; }
/* end */
--------------------
have_library: checking for PQconnectdb() in -llibpq... -------------------- no
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -llibpq "
ld: library not found for -llibpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
/* end */
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -llibpq "
conftest.c:16:13: error: conflicting types for 'PQconnectdb'
extern void PQconnectdb();
^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:16: note: previous declaration is here
extern PGconn *PQconnectdb(const char *conninfo);
^
conftest.c:17:27: error: too few arguments to function call, single argument 'conninfo' was not specified
int t(void) { PQconnectdb(); return 0; }
~~~~~~~~~~~ ^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:1: note: 'PQconnectdb' declared here
extern PGconn *PQconnectdb(const char *conninfo);
^
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: extern void PQconnectdb();
17: int t(void) { PQconnectdb(); return 0; }
/* end */
--------------------
have_library: checking for PQconnectdb() in -lms/libpq... -------------------- no
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -lms/libpq "
ld: library not found for -lms/libpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
/* end */
"clang -o conftest -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/arm64-darwin20 -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/rich/.rbenv/versions/2.7.2/include/ruby-2.7.0 -I. -I/Applications/Postgres.app/Contents/Versions/12/include -I/Users/rich/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -L/Applications/Postgres.app/Contents/Versions/12/lib -L. -L/Users/rich/.rbenv/versions/2.7.2/lib -fstack-protector-strong -Wl,-rpath,/Applications/Postgres.app/Contents/Versions/12/lib -lruby.2.7 -lms/libpq "
conftest.c:16:13: error: conflicting types for 'PQconnectdb'
extern void PQconnectdb();
^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:16: note: previous declaration is here
extern PGconn *PQconnectdb(const char *conninfo);
^
conftest.c:17:27: error: too few arguments to function call, single argument 'conninfo' was not specified
int t(void) { PQconnectdb(); return 0; }
~~~~~~~~~~~ ^
/Applications/Postgres.app/Contents/Versions/12/include/libpq-fe.h:263:1: note: 'PQconnectdb' declared here
extern PGconn *PQconnectdb(const char *conninfo);
^
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: int (* volatile tp)(void)=(int (*)(void))&t;
11: printf("%d", (*tp)());
12: }
13:
14: return !!argv[argc];
15: }
16: extern void PQconnectdb();
17: int t(void) { PQconnectdb(); return 0; }
/* end */
--------------------
I am having a similar problem after trying the following commands for Rails 5.0.7.2 running the latest version of postgres 13.
I'm using version '0.21.0' on my 10-year-old High Sierra computer running postgres 9.6.
sudo ARCHFLAGS="-arch x86_64" gem install pg -v '0.21.0'
sudo ARCHFLAGS="-arch x86_64" gem install pg -v '0.21.0' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -v '0.21.0' -- --with-libpq-lib
I can't find any documentation about these options.
With all the posts I've seen on Stack Overflow I wonder if the problem is with Big Sur. I've lost count of the number of older posts with similar errors.
NOTE: The last gem release (1.2.3) was on March 18, 2020. I hope that all contributors are okay since the COVID-19 pandemic started to hit around the world about that time.
Seeing the same problem here on an M1 MacBook Pro. The commonest solution I have seen online is to use libpq for the config sudo gem install pg -- --with-pg-config='/usr/local/opt/libpq/bin/pg_config' but that brings back the classic 'libpq-fe.h' file not found error, which also seems to be something people encountered frequently back in the day but rarely now.
Ah, I needed to find the libpq pg_confic, the /usr/local/opt path was wrong. Once I ran it with the exact /opt/homebrew/Cellar/libpq/13.3/bin/pg_config path, it came through for me.
installing pg with the following command worked for me:
arch -arm64 gem install pg
Generally those gems that are building with native extension and showing error can be resolved by using the prefix:
arch -arm64
Note: this is for M1 macs
If you are getting the following issue in Mac M1 pro, Silicon chip
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
Solution:
Install libpq via homebrew and add it to the PATH
brew install libpq
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
OR ~/bash_profile instead of ~/.zshrc if you use that.
Now try
bundle install # OR
gem install pg
This works for me.
That was not the specific trace I was seeing, but @abhilashak's answer worked for me on an M1 Mac running Ventura