title: ARM64 architecture (M1 chip): Cannot install pg gem (using PostgresApp)
body: <p>I've been trying to install a rails project on my computer (Macbook Pro 2020 with M1) running Big Sur.</p>
  <p>I have the PostgresApp installed.</p>
  <p>When running <code>bundle install</code> it fails to build the <code>pg</code> gem so I tried to install the gem manually (by doing <code>gem install pg</code> - tried also with <code>gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config</code>).</p>
  <p>I get an error saying:</p>
  <pre><code>ERROR:  Error installing pg:
  ERROR: Failed to build gem native extension.
  
  Can't find the PostgreSQL client library (libpq)
  *** extconf.rb failed ***
  </code></pre>
  <p>When checking the error logs I see:</p>
  <pre><code>have_library: checking for PQconnectdb() in -lpq... -------------------- no
  
  ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
  Undefined symbols for architecture arm64:
    &quot;_PQconnectdb&quot;, referenced from:
        _t in conftest-db479f.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 &quot;ruby.h&quot;
   2:
   3: #include &lt;libpq-fe.h&gt;
   4:
   5: /*top*/
   6: extern int t(void);
   7: int main(int argc, char **argv)
   8: {
   9:   if (argc &gt; 1000000) {
  10:     printf(&quot;%p&quot;, &amp;t);
  11:   }
  12:
  13:   return 0;
  14: }
  15: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
  /* end */
  </code></pre>
  <p>Any idea how to solve this?</p>