My app crashes because libc++ is missing.
-
This is under Mac OS. We have an all-CMake-based project.
If I build my app through Qt Creator, it runs fine. If I build it via a script that calls CMake, it crashes on launch with
Dyld Error Message: dyld: Using shared cache: 1D800E79-F93F-3FEF-9658-B168A649E2E4 Library not loaded: @rpath/libc++abi.1.dylib Referenced from: /Volumes/Cast/Cast.app/Contents/Frameworks/libc++.1.dylib Reason: image not foundLooking in the application bundle, I see that the one built by script contains a ton of frameworks under Frameworks, including libc++.1.dylib. The one built by Qt Creator contains none; thus I conclude that Qt Creator is building a statically-linked app and the script is building a dynamic one.
Obviously this raises some questions. First, why the difference in linkage? The script does this:
/Applications/CMake.app/Contents/bin/cmake -S $1 -B $BUILD_DIR -GNinja -DCMAKE_BUILD_TYPE:String=${BUILD_TARGET} -DQT_QMAKE_EXECUTABLE:STRING=$QT_DIR/bin/qmake -DCMAKE_PREFIX_PATH:STRING=$QT_DIR -DCMAKE_C_COMPILER:STRING=/usr/bin/gcc -DCMAKE_CXX_COMPILER:STRING=/usr/bin/clang++ -DCMAKE_MAKE_PROGRAM:STRING=$QT_ROOT_DIR/Tools/Ninja/ninjaLooking at the project settings in Qt Creator, I don't see where it specifies static vs. dynamic. I don't see it in the CMakeLists files either; that wouldn't explain why the two builds would vary anyway.
Also, why is libc++abi.1.dylib missing, when libc++.1.dylib isn't? On my system, these are found under Homebrew's control in usr/local/opt/lib. I have no idea how anything finds them, since there are no symlinks to them under /usr/lib or /usr/local/lib. But I guess that's academic, because they are being found or sourced from elsewhere.
Thanks for any suggestions on tracking this down!
-
Hi,
No, Qt Creator does not create static binaries like that. You would need a static version of Qt and all of the dependencies. Standard library like the C++ runtime is provided by the system.
You can use for example otool to see exactly what is linked to your executable.
Your script is likely doing something fishy.
-
Hi,
No, Qt Creator does not create static binaries like that. You would need a static version of Qt and all of the dependencies. Standard library like the C++ runtime is provided by the system.
You can use for example otool to see exactly what is linked to your executable.
Your script is likely doing something fishy.
@SGaist Thanks for that info.
otool -L on the app that runs shows:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)But why, when that file does not exist?
The app that crashes shows:@executable_path/../Frameworks/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)Every other lib appears to be the same between the two versions, typically
@rpath/QtQuickControls2.framework/Versions/5/QtQuickControls2 (compatibility version 5.15.0, current version 5.15.2) -
As I wrote, I don't know what your script does and I suspect there lies the issue.
-
@SGaist My question is regarding the otool output for the non-script-built application, the one built by Qt Creator, which runs. It claims that it's linked against
/usr/lib/libc++.1.dylib
This file does not exist on my system. So how can it be linked against?
As a solution to the overall problem, how can I capture the build commands used by Qt Creator so I can use them in place of whatever the script is doing?
I've tried (BUILD_DIR is passed into the script as a command-line parameter):
cmake --build $BUILD_DIR --target allbut the result is "Error: could not load cache." In the project build settings I see "Initial CMake parameters," but I don't know how to incorporate those into a scripted invocation.
-
If memory serves well, it's related to implicit system libs or something like that.
As for building with Qt Creator, it usually configures the build by pointing to the Qt version of your kit. You can find informations in the CMakefiles.txt.user file. Using ccmake in the build folder should also give you hints.
-
If memory serves well, it's related to implicit system libs or something like that.
As for building with Qt Creator, it usually configures the build by pointing to the Qt version of your kit. You can find informations in the CMakefiles.txt.user file. Using ccmake in the build folder should also give you hints.
@SGaist Thanks.
Is there a way to see the commands that are issued when you select "Run CMake" in Qt Creator? I tried pasting the contents of the "initial CMake parameters" into a call to cmake in a script, but I get
CMake Error at lib/lib_camera_match/src/CMakeLists.txt:3 (project): project could not find requested file: %{IDE:ResourcePath}/package-manager/auto-setup.cmakeThis is followed by tons of warnings like
ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. -
In the build panel.