"ld: duplicate symbol" issue in XCode cross-compilation - xcode

I am trying to cross-compile a project for the iOS (which is written in windows) and is based on openCV. And then I am trying to use these cross-compiled openCV libs for a specific application (called testApp).
I was first able to successfully cross-compile openCV for the iOS. Then I used these libraries to created another library called testLib.a which was consumed by an application testApp (which also used some openCV functionality).
The testLib.a compiled successfully but, for the testApp I had to add dependency to both testLib.a and the openCV libs (.a files). When I try to compile testApp, I get the following error -
ld: duplicate symbol cv::split(cv::Mat const&, cv::Mat*) in
/Users/suri/Projects/testLib/lib/Debug/libopencv_core.a(convert.o) and
/Users/suri/Projects/testApp/libs/testLib.a(convert.o) for
architecture i386
I can see that this error is probably coming because the openCV libs are added by open testLib as well as testApp. My question is should I try and reorganize the project or is there some other way to fix this issue?
I tried to find where the "split" function might actually be used in testLib but it does not seem to be called. Also, I have checked and every .h in the testLib as well as testApp and they all have a "ifndef" macro.

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"

Qt .pro combine libraries

I have a subdirs Qt project composed of :
an external (not made by me) lib
an internal (made by me) lib using the external lib
an application using the internal lib
I am on Windows using mingw as compiler
When compiling the libraries I have no issues, everything seems to work fine.
But when I compile the application, I get an ld error : undefined reference to external lib functions (called from internal libs function).
I think this is because when compiling the internal library these method are not called therefore not loaded and this is why it can't find them.
Is there a way to combine the 2 libraries (or at least to force the compiler/linker to resolve the symbols) when compiling the internal library ?
I found a way to fix my issue.
In the pro file of my internal lib :
I changed the TARGET value from internal_lib to internal_lib_unlinked.
I added a new line QMAKE_POST_LINK += ar crsT $$DESTDIR/libinternal_lib.a $$DESTDIR/libinternal_lib_unlinked.a path/to/libexternal_lib.a
This is hacky but it works.
Found thanks to How to combine several C/C++ libraries into one?

Xcode 12.4 Linking error: Library not found

I am using xcode 12.4 and In a macOS/OSX project I am getting a linking error Library not found.
The mac os app is using a C++ library that is being successfully built in the xcode workspace, but the linker fails to find it
I have added that dependency Cpp library in the "Link binary with Libraries" (Build phases)
I think my Library search paths setting in Build Settings is not correct, linker search hardcoded path which was set on different machine where project was first built.
The output of workspace which includes the C++ library is in the Derived data, how can I specify derived data or Build path as variable and use it to point to C++ library folder , so that even on different machine project is built without searching any hard coded library paths ?
Thanks,
Ahmed

"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.

Why does OMNet++ compiler gets errors for a precompiled package?

I have included an external package callled SoPlex (a folder of .cpp and .h files and the library files) into my OMNet++ project. I have already tested the package in Code::Blocks IDE and it works fine besides some warnings it had: warning: explicit conversion operators only available with -std=c++11 or -std=gnu++11.
It certainly was working in Code::Blocks IDE. But when I want to use it in my OMNet++ project it gives a lot of errors for the SoPlex package like in the picture:
It gives a lot of errors for just the code of SoPlex and not my OMNet++ project code.
Any idea what may cause the problem?
I have used MinGW to compile SoPlex package in Code::Blocks IDE. When I use MinGW GCC in OMNet++ instead of GCC for OMNet++ as current toolchain there is this error fatal error: omnetpp.h: No such file or directory.
Regarding the errors with the 3rd party library. Depending where you put the library inside the src folder, at least that directory must be added as an include dir, otherwise the header files will not be found by the compiler.
As for the problem with the omnetpp.h: OMNeT++ has it's own makefile generator which automatically adds the required include folder (omnetpp_root/include). The generic MinGW GCC toolchain does not. If you want to avoid extra work, always use the omnet toolchain to build your models.

Resources