ld: framework not found SDL2_image - c++

I want to use SDL2_image frameworks (an extension of SDL2 framework), i've downloaded and copied the SDL2_image frameworks in the folders below:
/Library/Frameworks/
/System/Library/Frameworks
/Users/ < user > /Library/Frameworks
my code works fine with SDL2 framework but when i add SDL2_image framework i get an error as follows:
ld: framework not found SDL2_image
clang: error: linker command failed with exit code 1 (use -v to see invocation)
i tried clearing my framework search path, tried to change my valid architecture section none of them has worked.

I solved the problem by changing the Base SDK option to Current OS X for both the Target and Modules
Instructions are as follows:
from project navigator select your project -> Select build Settings -> from architectures field change Base SDK to Current OS X.

Related

Xcode "ld: library not found" for C++ makefile project

OS: Mac 10.14.6 -- Xcode ver: 11.3.1
I have an external C++ project (that uses an existing makefile to build) that I imported into Xcode, and when I try to build it I get the following error message: ld: library not found for -ljpeg.
Strangely, when I run the same build command ($make all-recursive) from the command line, it builds successfully. I've double-checked and the relevant .dylib files DO exist in /usr/local/lib. From reading around the web it seemed like Xcode build-settings needed library search paths to include the directory where the .dylib files are, so I added LIBRARY_SEARCH_PATHS under target "Build Settings", but that did not solve the problem.
Is there any reason that comes to mind why Xcode's build command would fail but mine wouldn't?
Link should also receive a flag of the form -L<path> which has the path to the jpeg library's parent folder, before the -ljpeg flag.
So add -L/usr/local/lib to the other linker flags build setting and try again.
Easy way to find the correct flags is running pkg-config:
pkg-config --libs libjpeg
-L/usr/local/Cellar/jpeg/9d/lib -ljpeg
If that fails, you can:
Copy the dylib from its original location.
Paste it in a folder #executable_path/../Resources/lib. Create those folders if needed.
Then rebuild.
Most robust way is to pass the full path in -l option, and not break it in two components.

Resolve "ld: library not found for -ltensorflow_framework.2.3.0"

I'm trying to run a hello world macOS project that runs Tensorflow models. Documentation for Tensorflow (not to be confused by Tensorflow Lite) lack instructions on how to add the libtensorflow_framework to an XCode project that targets macOS.
What I did so far is:
create a conda environment (pip, python3.8.3)
pip install tensorflow==2.3.0rc0
locate the path to the tensorflow package, and drag and drop the libtensorflow_framework.2.3.0.dylib file into a group called lib that is located directly under the project root.
The I tried to run the app, but I got the following error:
ld: library not found for -ltensorflow_framework.2.3.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
which doesn't even make sense, because the file name is libtensorflow_framework.2.3.0.dylib and not ltensorflow_framework.2.3.0
So, I'm not sure what was the cause of that problem. However, I was able to finally link Tensorflow 2.2.0 to my Xcode project. (thanks to the hints that #Mikael H provided)
Here's what I did:
I installed TensorFlow using brew instead of python/pip.
brew install libtensorflow
I checked that /usr/local/include has the ./tensorflow/ headers and I added this path to the Xcode Header Search Path.
I checked that /usr/local/lib has the dylib files and added the path to Library Search Path.
I added the following arguments -ltensorflow -ltensorflow_framework.2.2.0 to the Other Linker Arguments.
You can find the Header Search Path, Library Search Path, and Other Linker Arguments by going to your target's settings -> Build Settings -> All & Combined.

How can I create a macOS .app bundle for a SFML game?

I'm on macOS and I'm compiling my game with
g++ -F Frameworks -rpath Frameworks {{frameworks}} src/main.cpp -o game
I was following instructions on apple developer documents
about how to create a macOS .app bundle, I have the correct folder structures and files but I still can't launch the app.
I got the error message:
Dyld Error Message:
Library not loaded: #rpath/sfml-window.framework/Versions/2.5.1/sfml-window
Referenced from: /Users/USER/*/test.app/Contents/MacOS/game
Reason: image not found
All of my framework bundles are in test.app/Contents/Frameworks and I'm able to run the binary in the Contents folder by ./MacOS/game. However it works if I just use the absolute path of the framework directory.
What should I pass as my -rpath argument?
According to this link, you need to have your rpath defined this way in the command line:
-rpath #executable_path/../Frameworks
That should tell it to look in AppBundle/Contents/Frameworks/ for all frameworks.
This is another good article on the subject.

How to compile OpenCV with extra modules on OS X?

I've previously compiled OpenCV 3.0 successfully following this guide, which essentially consists of the following steps:
Download all the prerequisites (XCode, Command Line Tools, CMake and OpenCV source)
Build static libs by configuring CMake (via gui) with:
Uncheck BUILD_SHARED_LIBS
Uncheck BUILD_TESTS
Add an SDK path to CMAKE_OSX_SYSROOT (if it matters, I used /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk).
Add x86_64 to CMAKE_OSX_ARCHITECTURES (emphasis mine, this seems to be the issue, I'm sure I've followed this step)
Uncheck WITH_1394
Uncheck WITH_FFMPEG
Configure and generate via CMake, then make and sudo make install from the CLI.
All of the above alone works fine.
I'm now looking to compile OpenCV with the extra modules. According to their read-me it should be as simple as filling out OPENCV_EXTRA_MODULES_PATH to <opencv_contrib>/modules in CMake and then building as usual.
I followed the steps outlined above with the added parameter and building OpenCV succeeds, however, when trying to use one of the extra modules in a program (namely cv::ximgproc::createStructuredEdgeDetection, if it matters), I'm getting the following error when compiling:
Undefined symbols for architecture x86_64:
"cv::ximgproc::createStructuredEdgeDetection(cv::String const&, cv::Ptr<cv::ximgproc::RFFeatureGetter const>)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've included the header which should include the above:
#include <opencv2/ximgproc.hpp>
I'm compiling via XCode, where I've set an additional header search path of /usr/local/include and a library search path of /usr/local/lib for the project, am I missing something here?
Standard OpenCV functionality works fine.
What could be the issue and how would I go about solving it?
OpenCV contrib modules are built correctly.
You just need to add the contrib libs to your dependencies, in this case adding: -lopencv_ximgproc.
All available libs can be found under <OPENCV_DIR>/install/ folder.
E.g. in my 32bit vc12 static build are in<OPENCV_DIR>/install/x86/vc12/staticlib folder.

How can I get Xcode to link and debug an app with Boost Filesystem?

TL;DR
Objective-C app linked with static library that dynamic links Boost Filesystem. App can be run from output directory using Terminal, but trying to run from Xcode debugger or Finder gives error dyld: Library not loaded: libboost_filesystem.dylib <snip> Reason: image not found.
Problem
In my Xcode project I have a structure that looks like this:
MainProject (Objective-C)
- static_lib_that_uses_filesystem (C++)
To get everything to link, I added libboost_system and libboost_filesystem dylibs to the "Link Binary with Libraries" build phase in MainProject.
When I try to run the app from either Xcode or Finder I get:
sharedlibrary apply-load-rules all
warning: Unable to read symbols for libboost_filesystem.dylib (file not found).
warning: Unable to read symbols from "libboost_filesystem.dylib" (not yet mapped into memory).
warning: Unable to read symbols for libboost_system.dylib (file not found).
warning: Unable to read symbols from "libboost_system.dylib" (not yet mapped into memory).
[Switching to process 43957 thread 0x0]
dyld: Library not loaded: libboost_filesystem.dylib
Referenced from: /Users/ssteele/Library/Developer/Xcode/DerivedData/MainProject-dqrhyuarllykslftblocjdzxlran/Build/Products/Debug/MainProject.app/Contents/MacOS/MainProject
Reason: image not found
I added a build stage to copy the dylibs to the Frameworks directory in the bundle, this doesn't help. I changed this to copy them to the Executables directory which also didn't help.
Having them in the Executables directory does allow me to run the app from Terminal.
How can I get the app to find the dylibs when run from Finder/Xcode?
Background Info
I'm using Xcode 4.2 on Lion and currently targeting Lion only. I built my shared libraries for filesystem like this:
./b2 threading=multi macosx-version=10.7 --with-filesystem stage
This creates libboost_system.dylib, libboost_filesystem.dylib, and also .a equivalents in the stage/lib directory, I'm referencing them in the project directly from there.
Dynamic libs (dylibs) on OSX bake in the path that they should be loaded from. For example...
/usr/lib/some_awesome.dylib.
When you link to a dylib, the linker embeds this path in your executable as the place to look for it at runtime. This is fine and easy with installed libs, but for relative path linking it's more complicated.
When you build the boost libs, they just get their names embedded rather than a full or relative path (i.e. libboost_system.dylib rather than /usr/lib/libboost_filesystem.dylib). You should be able to change this with the dll-path option, but that seems broken currently.
To fix your problem you either need to get the correct path relative to your application embedded (e.g. #executable_path/libwhatever.dylib) into the dylibs somehow, which would probably require the bjam dll-path option to work, or instead you can fix your executable to look in a different location.
To do this, use something like the following as a script step in your build:
install_name_tool -change libboost_filesystem.dylib #executable_path/libboost_filesystem.dylib$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH
Note that if you have multiple dylibs that reference each other with broken paths, you'll need to fix the paths between them too, e.g.
install_name_tool -change libboost_system.dylib #executable_path/libboost_system.dylib$BUILT_PRODUCTS_DIR/$EXECUTABLE_FOLDER_PATH/libboost_filesystem.dylib
The following is a good article on this: Creating working dylibs
The issue is that boost needs to be installed e.g. b2 ..... install. This copies the libraries and headers into /usr/local/lib and /usr/local/include.
OSX dynamic libraries only run from the directory that they are built for.
You can change the install directory by using the -prefix argument to boost build. However the libraries would still need to be in the same directory for all users.
There should be a way of building boost as a framework and/or embedding #executable_path in the library.
An alternative is to use boost's static libraries - build the static only or delete the dynamic ones, Xcode looks for dynamic before static. If using static then the path to the libraries does not matter at run time as all the code is now in the executable.
I think you need to add the path to the directory where you saved libboost_filesystem.a in the "library search paths"
Click on your project profile -> build settings -> expand "Search path" -> "library search paths"