Linking Error in Xcode and gtk - xcode

I am trying to build an interface with glade using C language and Xcode. I installed the library add added it to "other linker flags" in Xcode. I guess I am not linking it properly in the IDE. I get the following error:
"ld: library not found for -lgobject-introspection
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
How to properly link libraries in Xcode?

The answer is available in another post Linking Libraries in Xcode
The idea is to properly link the library in the linker flags like this:
-lgobject-introspection
then to add the path of the library in the Search header paths in Xcode.
This way, you tell Xcode to search the specified library in the added path.

Related

Xcode Library not found for -lavutil.57.28.100

I try to make macOS GUI application with ffmpeg.
On project settings -> General -> Frameworks,Libraries..., I added the ffmpeg lib files
/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib/libavutil.57.28.100.dylib.
I also add lib search path of /opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib
I still get error : Library not found for -lavutil.57.58.100.
I like to get more detail about error.
I think these possibility
not valid arm64 format.
linker expect x64 and arm64 binary. But the file has arm64 only.
Dependency of dylib is missing.
If someone knows solution or detail about this error, please let me know.
That file exist and valid arm64 Mach-O file.
file libavutil.57.28.100.dylib
libavutil.57.28.100.dylib: Mach-O 64-bit dynamically linked shared library arm64
Some tips that will help you to troubleshoot this issue.
Firstly, lldb expects an arm64 version of the lib if your main executable's architecture is arm64, a fat-universal version of the lib if your main executable's architecture is fat-universal.
So please check the main executable's architecture inside YOURAPP.app/Contents/MacOS. I'm taking IINA video player as an example:
lipo -i /Applications/IINA.app/Contents/MacOS/IINA
Secondly, it's not good to refer to a brew version of the binary. If the library's version on another machine mismatches with yours, your app will crash. It's ok that you copy the dylib file and copy it into your Xcode project. Then you can add the dylib file to the Frameworks, libraries, and Embedded Content section in Xcode. The below image shows an example of integrating ffmpeg libs into your project.
Alternatively, the ffmpeg-kit package is your friend. I have a simple showcase for you: Github
Finally, if you insist on using the brew version, please disable checking on code-signing for external libs: Project Settings > Signing & Capabilities > Hardened Runtime > Runtime Exceptions > Diable Library Validation
Xcode does not add library search path.
I add -L/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib on "Other Linker Flags"

About graphics.h, winbgim.h and libbgi.a libraries in codeblock

I added the full library graphic.h, winbgim.h, libbgi.a and its path in linker setting and other linker but it didn't work and it showed an error:
ld.exe cannot find -lbgi
ld will give you that error if it can't find libbgi.a for static builds or libbgi.dll.a shared builds.
Make sure the path containing libbgi.a is set it the linker paths as in this screenshot:
Another thing you could try is to build a static version of your project in order to avoid using a missing shared library.

Where are Linker Flags in External C Library?

I have a C library which I need to use in my ongoing Xcode project. I used Cmake to build and install that Library. I gave the paths to Headers files and I can include the files into my Xcode project. However, when I run the project it says:
linker command failed with exit code 1 (use -v to see invocation)
I suspect that problem is with Linker Flags. I haven't included any Linker Flags and I don't know which flags do I need to add. Please tell me where in the library would I get all the required Linker Flags.
git hub link of the library which I want to add:
https://github.com/cbalint13/pba
From xcode left side window.
Under Project Navigator, click on your project, click on build settings.
Select "All" and "Combined" sections, then search for "Linker Flag"
Don't forget to switch to your target's build settings as well. As you might change just the "Project", not the "Target".

"Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib" with Xcode 8?

My project requires OpenSSL libraries crypto and ssl. After updating Xcode to 8.2.1, compiling my project fails.
In my project Build Settings, in Linking, I have -lssl -lcrypto -lxml2 that indicates to load those libraries. Going back to my app Build Settings, I add /usr/local/opt/openssl/lib/ in the Library Search Paths to tell Xcode where to look.
Hurray, it compiles, builds and run properly. Cool.
BUT
When launching the app on a different mac, the app crashes, with this linking error:
Dyld Error Message:
Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /Applications/MyApp.app/Contents/MacOS/MyApp
Reason: image not found
That means the app is trying to load the open ssl libraries that might not be present on that mac. There might be just an older version, or that folder might not exist at all? So that's definitely a no-solution.
Here lies my issue, I have no idea how to solve this problem.
Removing -lssl -lcrypto from the linking doesn't help, as the has errors during linking.
I guess I need a way to tell Xcode to look there when compiling only. Would that be possible?
If you don't wish to ship libraries and deal with making sure the linker can find them, you can link your code against a static library.
Using the code in this question as a linking example, I compiled with this command:
cc -I/opt/homebrew/Cellar/openssl#1.1/1.1.1q/include -o Link14 Link14.cpp /opt/homebrew/Cellar/openssl#1.1/1.1.1q/lib/libcrypto.a -lc++
This uses system libraries for most things, but the static version of libcrypto in libcrypto.a for the encryption. You can add multiple by placing them on the compile/link line.

libcocos2d tvOS.a(bio_lib.o)' does not contain bitcode

When compiling cocos2d-js for AppleTV project I receive this error:
ld: '/Users/pepa/Library/Developer/Xcode/DerivedData/GameXY-gwkkxwmtiilmalhdxfdjgqdfhedy/Build/Products/Debug-appletvos/libcocos2d
tvOS.a(bio_lib.o)' does not contain bitcode. You must rebuild it with
bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated
library from the vendor for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe that I've included only libs built for AppleTV target with bitcode enabled. But the compiler is still complaining. Is the hint to tell which library miss the bitcode in the brackets? (bio_lib.o)
If so, would you know which library it belongs to? I did not find it on my computer.
I'm using the prebuilt binaries from here: https://github.com/elvman/cocos2d-x-3rd-party-libs-bin/tree/tvos
Use next steps:
Install git, make, autoconf, automake, libtool. If you are using Homebrew this can be done by:
brew install git make autoconf automake libtool
Clone repository:
git clone https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src.git
Go to cocos2d-x-3rd-party-libs-src/build and change 2 lines in file tvos.ini:
cfg_build_release_mode="-O3 -DNDEBUG -fembed-bitcode"
cfg_build_debug_mode="-O0 -g -DDEBUG -fembed-bitcode"
Run build script:
build.sh -p=tvos --libs=curl --arch=arm64,x86_64 --mode=release
update libcurl.a crypto and ssl library
Ok for anyone coming here trying to build cocos2d-x (3.10) for iOS using Bitcode enabled. I did it, based on the answer of user1675169 ( https://stackoverflow.com/a/33969215/129202 ) but of course I replaced the os in the build.sh line, and I had to replace all of these one by one:
libtiff.a
libwebp.a
libchipmunk.a
libjpeg.a
libpng.a
libfreetype.a
It took me a while to replace each and everyone of these. Depending on what you use in your cocos2d-x project, you might need to replace other libraries as well. Probably in the end cocos2d-x 3.11 will be delivered with all of these libraries recompiled with bitcode enabled in the first place.
A recompile line could look like this:
build.sh -p=ios --libs=tiff --arch=arm64,x86_64 --mode=release
In the end I was able to precompile the whole libcocos2d with bitcode enabled. I haven't tried sending this to iTunes Connect yet but I guess it might actually work in the end.

Resources