title: Undefined reference when linking libpq in C++ project
body: <p>I am trying to use <code>libpqxx</code> (and implicitly <code>libpq</code>) in a C++ project.<br />
  I use <code>vcpkg</code> as a <code>submodule</code> to get my libs by setting <code>CMAKE_TOOLCHAIN_FILE</code>.</p>
  <p>When I try to build, I get the following errors:</p>
  <pre><code>/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `pg_fe_sendauth':
  fe-auth.c:(.text+0x4fe): undefined reference to `pg_md5_encrypt'
  /usr/bin/ld: fe-auth.c:(.text+0x51b): undefined reference to `pg_md5_encrypt'
  /usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `pg_fe_getauthname':
  fe-auth.c:(.text+0x838): undefined reference to `pqGetpwuid'
  /usr/bin/ld: fe-auth.c:(.text+0x8a4): undefined reference to `pg_strerror_r'
  /usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `PQencryptPassword':
  fe-auth.c:(.text+0x936): undefined reference to `pg_md5_encrypt'
  /usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `PQencryptPasswordConn':
  fe-auth.c:(.text+0x9ed): undefined reference to `pg_md5_encrypt'
  /usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth-scram.o): in function `build_client_final_message':
  fe-auth-scram.c:(.text+0xdb): undefined reference to `scram_SaltedPassword'
  /usr/bin/ld: fe-auth-scram.c:(.text+0xee): undefined reference to `scram_ClientKey'
  /usr/bin/ld: fe-auth-scram.c:(.text+0xfe): undefined reference to `scram_H'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x113): undefined reference to `scram_HMAC_init'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x12d): undefined reference to `scram_HMAC_update'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x141): undefined reference to `scram_HMAC_update'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x15b): undefined reference to `scram_HMAC_update'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x16f): undefined reference to `scram_HMAC_update'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x185): undefined reference to `scram_HMAC_update'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x195): undefined reference to `scram_HMAC_final'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x1e4): undefined reference to `pg_b64_enc_len'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x213): undefined reference to `pg_b64_encode'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x344): undefined reference to `pg_b64_enc_len'
  /usr/bin/ld: fe-auth-scram.c:(.text+0x368): undefined reference to `pg_b64_encode'
  ...
  </code></pre>
  <p>I have broken down the linking command here:</p>
  <pre><code>/usr/bin/cmake -E cmake_link_script CMakeFiles/hello-pq.dir/link.txt --verbose=1
  /usr/bin/c++     CMakeFiles/hello-pq.dir/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp.o CMakeFiles/hello-pq.dir/main.cpp.o  
  -o ../bin/hello-pq  
  /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libssl.a 
  /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libcrypto.a 
  /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libpqxx-7.3.a 
  -lpthread 
  /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a -ldl 
  </code></pre>
  <p>My <code>CMakeLists.txt</code> looks like this:</p>
  <pre><code>cmake_minimum_required(VERSION 3.16)
  
  set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake
          CACHE STRING &quot;Vcpkg toolchain file&quot;)
  
  project(hello-pq)
  
  set(CMAKE_CXX_STANDARD 20)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  
  set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
  
  find_package(OpenSSL REQUIRED) 
  find_package(libpqxx CONFIG REQUIRED)
  
  file(GLOB_RECURSE PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
  add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
  
  target_link_libraries(${PROJECT_NAME}
                          PRIVATE OpenSSL::SSL 
                          PRIVATE OpenSSL::Crypto
                          PRIVATE libpqxx::pqxx)
  </code></pre>
  <p>I looked at the <code>libpq.a</code> from <code>vcpkg</code> <em>installed</em> dir with <code>nm</code> and I can see that for example, <code>pg_md5_encrypt</code> appears as <strong>undefined</strong>:</p>
  <pre><code>U pg_md5_encrypt
  </code></pre>
  <p>I don't get it, where are these missing functions like <code>pg_md5_encrypt</code>?<br />
  Is there another <code>libpq...</code> that I need to link or maybe a different version?</p>