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

Can't install version 2.1.3 on MacOS 12.6 Monterey with ARM Apple Silicon #255

Closed
nicmarti opened this issue Sep 15, 2022 · 12 comments · Fixed by #256
Closed

Can't install version 2.1.3 on MacOS 12.6 Monterey with ARM Apple Silicon #255

nicmarti opened this issue Sep 15, 2022 · 12 comments · Fixed by #256

Comments

@nicmarti
Copy link

pg_query version 2.1.3 won't install on MacOS 12.6 Monterey with an arm64 Ruby 3.1.2

Here is the error message extracted from a bundle install

Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1

make failed, exit code 2

More details about the environment :

ruby -v
  ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

bundler --version
  Bundler version 2.2.32

Also if I try to run a make from the .rbenv folder =>

cd $HOME/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/pg_query-512169280fea/ext/pg_query

➜  pg_query git:(main) ✗ make
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1

Any help or ideas are welcome

@nicmarti
Copy link
Author

I found one of my colluegue that has the same architecture/same os but for which it did work.
Here is a diff on the Makefile (note: I filtered the path so that the diffs is showing only what is different)

On the left : this Makefile compiles on my machine, on the right (pg_query_nic) is the one that does not work

35,36c35,36
< sitearchdir = $(DESTDIR)./.gem.20220711-23629-tjpu0c
< sitelibdir = $(DESTDIR)./.gem.20220711-23629-tjpu0c
---
> sitearchdir = $(DESTDIR)./.gem.20220915-29713-qlv927
> sitelibdir = $(DESTDIR)./.gem.20220915-29713-qlv927
94c94
< dldflags = -L/Users/nmartignole/.rbenv/versions/3.1.2/lib  -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-exported_symbols_list /Users/nmartignole/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/pg_query-512169280fea/ext/pg_query/pg_query_ruby.sym 
---
> dldflags = -L/Users/nmartignole/.rbenv/versions/3.1.2/lib  -Wl,-multiply_defined,suppress -Wl,-exported_symbols_list /Users/nmartignole/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/pg_query-512169280fea/ext/pg_query/pg_query_ruby.sym 
119,120c119,120
< MAKEDIRS = mkdir -p
< INSTALL = /usr/bin/install -c
---
> MAKEDIRS = /usr/local/bin/gmkdir -p
> INSTALL = /usr/local/bin/ginstall -c```

@nicmarti
Copy link
Author

I see that -undefined,dynamic_lookup is missing on the version that does not compile.

@mgallagher0
Copy link

I've been having this same issue, I can install version 1.3.0 but not 2.1.3.

@stanhu
Copy link
Contributor

stanhu commented Sep 16, 2022

See https://bugs.ruby-lang.org/issues/19005 for a workaround.

@stanhu
Copy link
Contributor

stanhu commented Sep 16, 2022

This makes me wonder if the visibility setting in

__attribute__((visibility ("default"))) void Init_pg_query(void)
is needed.

@stanhu
Copy link
Contributor

stanhu commented Sep 16, 2022

I've confirmed that reverting #232 works on macOS. In Linux, -undefined,dynamic_lookup is the default, but it's not always available on macOS and other platforms.

@stanhu
Copy link
Contributor

stanhu commented Sep 16, 2022

#256 fixes this issue.

stanhu added a commit to stanhu/pg_query that referenced this issue Sep 16, 2022
`Init_pg_query` isn't actually exported, but `_Init_pg_query` is:

```
% nm pg_query_ruby.o | grep Init
0000000000000000 T _Init_pg_query
0000000000003b40 b _Init_pg_query.rb_intern_id_cache
```

A Ruby compiler compiled with XCode 14 without the flag
`-undefined,dynamic_lookup` will see this error:

```
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1
```

Closes pganalyze#255
@namrata-vts
Copy link

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

I can workaround the problem by doing:

gem install pg_query -- --with-ldflags="-Wl,-undefined,dynamic_lookup"

@stanhu
Copy link
Contributor

stanhu commented Sep 17, 2022

It looks like there is an upstream Ruby fix for this problem: ruby/ruby@6898984

It'd be nice if this were backported.

stanhu added a commit to stanhu/pg_query that referenced this issue Sep 17, 2022
`Init_pg_query` isn't actually exported, but `_Init_pg_query` is:

```
% nm pg_query_ruby.o | grep Init
0000000000000000 T _Init_pg_query
0000000000003b40 b _Init_pg_query.rb_intern_id_cache
```

A Ruby compiler compiled with XCode 14 without the flag
`-undefined,dynamic_lookup` will see this error:

```
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1
```

Closes pganalyze#255
stanhu added a commit to stanhu/pg_query that referenced this issue Sep 17, 2022
`Init_pg_query` isn't actually exported, but `_Init_pg_query` is:

```
% nm pg_query_ruby.o | grep Init
0000000000000000 T _Init_pg_query
0000000000003b40 b _Init_pg_query.rb_intern_id_cache
```

A Ruby compiler compiled with XCode 14 without the flag
`-undefined,dynamic_lookup` will see this error:

```
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1
```

In pganalyze#222, FreeBSD needed `Init_pg_query`, so we FreeBSD uses its own
exported symbols file.

Closes pganalyze#255
stanhu added a commit to stanhu/pg_query that referenced this issue Sep 17, 2022
`Init_pg_query` isn't actually exported, but `_Init_pg_query` is:

```
% nm pg_query_ruby.o | grep Init
0000000000000000 T _Init_pg_query
0000000000003b40 b _Init_pg_query.rb_intern_id_cache
```

A Ruby compiler compiled with XCode 14 without the flag
`-undefined,dynamic_lookup` will see this error:

```
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1
```

In pganalyze#222, FreeBSD needed `Init_pg_query`, so we uses a specific symbol
map file for FreeBSD.

Closes pganalyze#255
lfittl pushed a commit that referenced this issue Sep 17, 2022
`Init_pg_query` isn't actually exported, but `_Init_pg_query` is:

```
% nm pg_query_ruby.o | grep Init
0000000000000000 T _Init_pg_query
0000000000003b40 b _Init_pg_query.rb_intern_id_cache
```

A Ruby compiler compiled with XCode 14 without the flag
`-undefined,dynamic_lookup` will see this error:

```
linking shared-object pg_query/pg_query.bundle
Undefined symbols for architecture arm64:
  "Init_pg_query", referenced from:
     -exported_symbol[s_list] command line option
     (maybe you meant: _Init_pg_query)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_query.bundle] Error 1
```

In #222, FreeBSD needed `Init_pg_query`, so we uses a specific symbol
map file for FreeBSD.

Closes #255
@nicmarti
Copy link
Author

Thanks for the quick fix

@asadakbar
Copy link

Leaving this for anyone else that hits this issue - I couldn't update my pg_query version so downgrading the Xcode version from 14 to 13 fixed this issue for me.

@lfittl
Copy link
Member

lfittl commented Oct 21, 2022

@asadakbar Thanks for adding the note - curious what was challenging about updating your pg_query version? (maybe another gem requiring a different protobuf gem version?)

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

Successfully merging a pull request may close this issue.

6 participants