iOS Framework: image not found - c++

When trying to embed a shared Framework generated from CMake into an Xcode iOS app, I encounter the following issue:
dyld: Library not loaded: /Users/jones/Documents/project/build/ios/foo.framework/foo
Referenced from: /var/Containers/Bundle/Application//myapp.app/myapp
Reason: image not found
It seems like it has an incorrect "dylib id", but I am not sure what that means exactly. Note that my framework appears in the "Frameworks" folder of the app (the built "Product" that is installed on the phone).
Checking my app with otool -L, I see:
myapp:
/Users/name/Documents/project/build/ios/foo.framework/foo
/System/Library/Frameworks/Foundation.framework/Foundation
/usr/lib/libobjc.A.dylib
...
Which seems to show that the path to my framework is wrong in the app. But I can't seem to change it from Xcode.
On the Apple dev forum, somebody mentions changing DYLIB_INSTALL_NAME_BASE to #rpath from Build Settings -> Dynamic Library Install Name Base, but it doesn't solve my problem.
The linker log coming from Xcode looks like so (maybe easier to read here:
Ld /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos/myapp.app/myapp normal arm64
cd /Users/jones/Documents/project/ios-playground/myapp
export IPHONEOS_DEPLOYMENT_TARGET=11.2
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -L/Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos -F/Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos -F/Users/jones/Documents/project/ios-playground/myapp -F/Users/jones/Documents/project/ios-playground/myapp/Frameworks -filelist /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp.LinkFileList -Xlinker -rpath -Xlinker #executable_path/Frameworks -miphoneos-version-min=11.2 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -stdlib=libc++ -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -add_ast_path -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp.swiftmodule -framework foo -Xlinker -dependency_info -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp_dependency_info.dat -o /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos/myapp.app/myapp
How can I fix this?

There is actually a way to set the "install_name_dir" in CMake:
set_target_properties(dynamicFramework PROPERTIES
...
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_NAME_DIR #rpath
)

Related

How to use own openssl header in libcurl on macOS

I download and compile openssl 3.0.2 from source and want to link it with libcurl on macOS, however, I encounter some issues, I use latest libcurl 7.82.0.
below is configure.
./configure --prefix="$(pwd)/curl" --with-ssl=/Users/test/Downloads/openssl-openssl-3.0.2/openssl --enable-static --disable-shared --disable-ftp --disable-file --disable-ldap --disable-dict --disable-telnet --disable-tftp --disable-rtsp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-ares --disable-debug --with-zlib=/Users/test/Downloads/zlib-1.2.11/zlib --without-libidn --without-brotli --without-zstd --without-nghttp2 --without-librtmp --without-libidn2 --without-winidn
and configure result looks ok, The openssl include folder is set.
Host setup: x86_64-apple-darwin20.6.0
Install prefix: /Users/test/Downloads/curl-7.82.0/curl
Compiler: gcc
CFLAGS: -Qunused-arguments -Wno-pointer-bool-conversion -Os -Werror=partial-availability -pthread
CPPFLAGS: -isystem /Users/test/Downloads/zlib-1.2.11/zlib/include -isystem /Users/test/Downloads/openssl-openssl-3.0.2/openssl/include -DOPENSSL_SUPPRESS_DEPRECATED
LDFLAGS: -framework CoreFoundation -framework SystemConfiguration -L/Users/test/Downloads/zlib-1.2.11/zlib/lib -L/Users/test/Downloads/openssl-openssl-3.0.2/openssl/lib
LIBS: -lssl -lcrypto -lssl -lcrypto -lz
curl version: 7.82.0
SSL: enabled (OpenSSL v3+)
But when make, it will output error:
Undefined symbols for architecture x86_64:
"_EVP_PKEY_id", referenced from:
_ossl_connect_common in libcurl.a(libcurl_la-openssl.o)
"_SSL_get_peer_certificate", referenced from:
_ossl_connect_common in libcurl.a(libcurl_la-openssl.o)
ld: symbol(s) not found for architecture x86_64
Test:
I found os installed openssl at /usr/local/include/openssl which is 1.1.1m, After I remove this folder, The error is fixed. So I think the system installed openssl header is affected in libcurl make.
I think I have configured libcurl to use /Users/test/Downloads/openssl-openssl-3.0.2/openssl/include, but it does not work.
Thanks in advance.
I have the same problem with openSSL#3. I change to use openssl#1.1/1.1.1s and libcurl and it's working.

OpenGL Link Error for GLFW DDS Load function

I have been working my way through the OpenGL-tutorial.org tutorial series. All has been working fine, however I have not been able to get Tutorial 5 to work in my playground executable, though it does work when run from the example tutorial 5 executable. This is true even when I copy and paste the example code over.
I receive the following errors:
Undefined symbols for architecture x86_64:
"loadDDS(char const*)", referenced from:
_main in playground.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Below is the link log:
Ld playground/playground normal x86_64
cd /Users/RufusVijayaratnam/rufus/Coding/ogl-master
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -F/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -filelist /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_lto.o -Xlinker -no_deduplicate -Wl,-search_paths_first -Wl,-headerpad_max_install_names -framework OpenGL -framework OpenGL /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/glfw-3.1.2/src/Debug/libglfw3.a /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/Debug/libGLEW_1130.a -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo -Xlinker -dependency_info -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_dependency_info.dat -o /Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground/playground
So the error appears to be that when the function loadDDS() is called that it is not found. I am unsure as to why this is. The function is declared in texture.ccp which is in a folder (called 'common'), along with texture.hpp. texture.hpp has the code below:
#ifndef TEXTURE_HPP
#define TEXTURE_HPP
// Load a .DDS file using GLFW's own loader
GLuint loadDDS(const char * imagepath);
#endif
In playground.cpp there is:
include<texture.hpp>
Why can't loadDDS() be found, even though I have set the working directory of the playground function to the same as that for Tutorial 5, and the code in playground.ccp and 'tutorial05.ccp' is exactly the same?
for the playground executable (doesn't work)
# User playground add_executable(playground
playground/playground.cpp
common/shader.cpp
common/shader.hpp )
and finally for tutorial 5 (does work)
# Tutorial 5
add_executable(tutorial05_textured_cube
tutorial05_textured_cube/tutorial05.cpp
common/shader.cpp
common/shader.hpp
common/texture.cpp
common/texture.hpp
So I'm making the educated guess that loadDDS() is implemented in texture.cpp, and since you did not add this file, it won't be compiled, and the resulting object file won't be linked, and the symbol will just not be found.

Linker error with GLFW on OS 10.10

I'm trying to compile the following
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
return 0;
}
just to verify that my GLFW installation is working. I use the terminal with
clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c
but I receive a linker error for the glfwInit function:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64
I have installed glfw with sudo port install glfw and followed every possible tutorial I've found. I can verify that the libglfw.dylib file can be found at /opt/local/lib/ as (I think) it should.
Any suggestions?
You need to link with GLFW[3] as well, e.g., add:
-L/opt/local/lib -lglfw3
If you have the pkgconfig port installed, you can also take advantage of that with:
clang `pkg-config glfw3 --cflags` test.c -o test \
`pkg-config glfw3 --static --libs`
You may not need the --static flag if you have: libglfw3.dylib, as opposed to using: libglfw3.a, but it doesn't hurt.
If you are using Xcode, you must add the libglfw3.a library when linking binaries.
Heres the trick
Show hidden folders. Paste this into terminal: defaults write com.apple.finder AppleShowAllFiles YES
Relaunch a finder window and navigate to Macintosh HD\usr
Drag the usr folder to the "Favorites" side in the terminal
In xcode, click the add "+" to link binaries, then click "Add Other"
navigate to the libglfw3.a and add it!
If it still does not work, here are some instructions that helped me.
https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400

Apple Mach-O Linker Error - duplicate symbols

I'm having a little trouble with an app I'm making. I researched this a bit and looked at other posts, but the fixes that they proposed don't work for me. I am running all the latest softwares.
It says:
3 duplicate symbols for architecture i386
Linker command failed with exit code 1 ( use -v to see invocation)
Ld
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator/People\
Bingo.app/People\ Bingo normal i386
cd "/Users/RileyLloyd/Documents/Xcode/People Bingo"
setenv IPHONEOS_DEPLOYMENT_TARGET 7.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
-L/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator
-F/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator
-filelist /Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People\
Bingo.build/Debug-iphonesimulator/People\
Bingo.build/Objects-normal/i386/People\ Bingo.LinkFileList -Xlinker
-objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.0 -framework CoreData -framework CoreGraphics -framework UIKit -framework
Foundation -Xlinker -dependency_info -Xlinker
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People\
Bingo.build/Debug-iphonesimulator/People\
Bingo.build/Objects-normal/i386/People\ Bingo_dependency_info.dat -o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator/People\
Bingo.app/People\ Bingo
duplicate symbol _OBJC_IVAR_$_CollectionViewController._cellArray in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o duplicate
symbol _OBJC_CLASS_$_CollectionViewController in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o duplicate
symbol _OBJC_METACLASS_$_CollectionViewController in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o ld: 3
duplicate symbols for architecture i386 clang: error: linker command
failed with exit code 1 (use -v to see invocation)
Two modules in your application (ViewController and CollectionViewController) have provided an implementation of class CollectionViewController. The three duplication symbols are class metadata.
There are a number of ways you might have done this:
You have two modules declaring the same class. Perhaps one is vestigial?
The #implementation CollectionViewController appears in a .h file that is included in both CollectionViewController.m and ViewController.m - or you included a .m file somewhere.

library not found for.....?

i added new framework(3rd party) and build.
Unfortunately, since the execution was not.
How do I solve this problem?
The whole four nights were spent.:(
Ld /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos/iBaseballManager.app/iBaseballManager normal armv7s
cd /DevLibs/BaseballManager_KOR/iBaseballManager
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -L/Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos -L/DevLibs/BaseballManager_KOR/iBaseballManager/Classes/BaseballManager/kakaoUtil/kakao-ios-sdk -F/Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos -filelist /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Intermediates/iBaseballManager.build/Distribution-iphoneos/iBaseballManager_Device.build/Objects-normal/armv7s/iBaseballManager.LinkFileList -dead_strip -fobjc-link-runtime -miphoneos-version-min=6.0 -framework StoreKit -framework SystemConfiguration -framework CoreData -weak_framework AdSupport -framework MediaPlayer -framework CoreTelephony -framework Security -lzlib -lstdc++ -lCxImage -lj2k -ljasper -lkakao-ios-sdk-i386-armv7-armv7s -ljbig -ljpeg -lpng -ltiff -framework AudioToolbox -framework AVFoundation -framework Foundation -framework UIKit -framework CoreGraphics -framework OpenAL -framework OpenGLES -framework QuartzCore -liClet -Xlinker -dependency_info -Xlinker /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Intermediates/iBaseballManager.build/Distribution-iphoneos/iBaseballManager_Device.build/Objects-normal/armv7s/iBaseballManager_dependency_info.dat -o /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos/iBaseballManager.app/iBaseballManager
ld: library not found for -lzlib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Remove the reference to the library and add it again, it will solve the problem.
Use xcworkspace it will solve your problem.
I also faced same once I install cocoa pods; Close and launch with xcworkspace again will solve your problem.
Make sure you have added the necessary search path for your library in Library Search Paths in Build Settings.
There should be something like:
${SOURCE_ROOT}/Framework/Classes
For .a files you need to set Target Dependencies in Build Phases in section.
Just click "+" and add your .a file there.
Had the same problem and none of these answers fix it for me.
Problem was Pod project in workspace had the following config:
Build Active Architecture Only: YES
For that reason, when I wanted to build for i386 (Simulator), XCode did not build Pods projects, so it could not meet dependencies. As soon as I changed it to NO it started working
If anyone is here looking specifically for the "library not found for -lPods" error, this was solved by opening the workspace instead of the xcodeproject. Searching google for library not found for -lPods without quotes turns this SO post as the first result, whereas if you wrap the search in quotes you'll get a post with the answer I just gave.
I changed -all_load to -force_load
In Xcode goto select your project
Build Settings -> Search Paths -> Library Search Paths set the path with /usr/local/lib
note : make sure that you have added dylib at frameworks
OS X 10.11 Xcode7.0.1
my case:
library not found for -lPods-BlocksKit
error:linker command failed with exit code 1(use -v to see invocation)
I delete all pod related content, add "$(inherited)" then fix it.
Other Linker Flags image
my case: use cocoapods, open xcworkspace, and meet "library not found for -lPods-AFNetworking" error.
my solution: Preference -> Location -> Derived Data, click "Advanced" button -> choose 'shared Folder'. (when meet error, the original location is Legacy).
None of the above solutions worked for me, so I downloaded the missing library:
https://github.com/danielctull-forks/GoogleAnalytics-SDK-iOS
7.3.1 Pods 1.0.0
Had same stuff today, after cocoapods update from 0.39.0 to 1.0.0.
Had an error : "ld: library not found -lPods".
I've got linked two "Pod" libs, accidentally. One was lPods, and other was lPods-ProjectName. I deleted "libPods.a: from Project>General>Linked Frameworks and Libraries
AND! I changed Pods>Build Active Build Architecture to NO, of course.
And it worked.