Compiled app uses system dylib instead of supplied dylib

Using Xcode Version 11.4 (11E146) on macOS Catalina 10.15.4 (19E266).


I am building a macOS app that requires libpq from postgresql.


The problem that I am facing is that when running my xcode built app, it uses an unknown libpq that reports version 9.3.7 (maybe provided by the sytem) no matter how I try to get Xcode to use the MacPorts libpq located at `/opt/local/lib/postgresql11/libpq.5.11.dylib` which should report as version 11.07.


I determine the client library version by examing the results from the libpq function call `PQlibVersion()`


Here is what I have tried. Between each attempt the project was cleaned.


1. Add `/opt/local/lib/postgresql11/libpq.5.11.dylib` to target -> General -> Frameworks, Libraries, and Embedded Content. Select "Do Not Embed". Compiles, runs, does NOT work, still uses system libpq.


% otool -L MyApp.app/Contents/MacOS/MyApp

MyApp.app/Contents/MacOS/RushRadioSQLDataProcessing:

@rpath/CSV.framework/Versions/A/CSV (compatibility version 1.0.0, current version 1.0.0)

@rpath/ObjcExceptionBridging.framework/Versions/A/ObjcExceptionBridging (compatibility version 1.0.0, current version 1.0.0)

@rpath/XCGLogger.framework/Versions/A/XCGLogger (compatibility version 1.0.0, current version 1.0.0)

/System/Library/Frameworks/CloudKit.framework/Versions/A/CloudKit (compatibility version 1.0.0, current version 867.0.0)

/opt/local/lib/postgresql11/libpq.5.dylib (compatibility version 5.0.0, current version 5.11.0)

/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1675.129.0)

/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1894.40.150)

/System/Library/Frameworks/CoreData.framework/Versions/A/CoreData (compatibility version 1.0.0, current version 977.3.0)

/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1675.129.0)

/System/Library/Frameworks/CoreLocation.framework/Versions/A/CoreLocation (compatibility version 1.0.0, current version 2394.0.22)

@rpath/libswiftCloudKit.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1103.8.25)

@rpath/libswiftCoreData.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftDispatch.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 0.0.0)


2. Add `/opt/local/lib/postgresql11/libpq.5.11.dylib` to target -> General -> Frameworks, Libraries, and Embedded Content. Select "Embed & Sign". Compiles, runs, does NOT work, still uses system libpq. Does NOT work, still uses system libpq.


% otool -L myApp.app/Contents/MacOS/MyApp:

@rpath/CSV.framework/Versions/A/CSV (compatibility version 1.0.0, current version 1.0.0)

@rpath/ObjcExceptionBridging.framework/Versions/A/ObjcExceptionBridging (compatibility version 1.0.0, current version 1.0.0)

@rpath/XCGLogger.framework/Versions/A/XCGLogger (compatibility version 1.0.0, current version 1.0.0)

/System/Library/Frameworks/CloudKit.framework/Versions/A/CloudKit (compatibility version 1.0.0, current version 867.0.0)

/opt/local/lib/postgresql11/libpq.5.dylib (compatibility version 5.0.0, current version 5.11.0)

/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1675.129.0)

/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1894.40.150)

/System/Library/Frameworks/CoreData.framework/Versions/A/CoreData (compatibility version 1.0.0, current version 977.3.0)

/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1675.129.0)

/System/Library/Frameworks/CoreLocation.framework/Versions/A/CoreLocation (compatibility version 1.0.0, current version 2394.0.22)

@rpath/libswiftCloudKit.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1103.8.25)

@rpath/libswiftCoreData.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftDispatch.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)

@rpath/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 0.0.0)


3. Add `/opt/local/lib/postgresql11/libpq.5.11.dylib` to target -> General -> Frameworks, Libraries, and Embedded Content. Select "Embed without Signing". Does not compile. Error App code object is not signed at all In subcomponent: MyApp.app/Contents/Frameworks/libpq.5.11.dylib


When I sampled the running app I found that it shows the following lib being used.


libpq.5.dylib (207.14) <72EB7D5B-B6AB-3BBE-877D-C01637C38548> /usr/lib/libpq.5.dylib


Why is it using this lib and not the version specified in the Xcode build instructions?

Compiled app uses system dylib instead of supplied dylib
 
 
Q