manage order of static link for IOS in XCode - c++

QUESTION: how to manage linking order in xcode?
DETAILES:
I'm new in Apple-dev and have some troubles with building my project for ios.
I'm building OGRE3d(1.10) and MyGUI(3.2) libraries from source code via cmake and ios-toolchain.cmake.
MyGUI using functions from ogre and I like them using cmake function target_link_library. And I have any .a static libraries. We will name them ogre.a and mygui.a.
Then I've create ios project and create Objective-c++ file(.mm) where tried to use mygui and ogre function. To link mygui and ogre i've drag them and drop to the root of project structure of xcode and i see them in "linked framework and libraries".
But I have linking errors, which says that ogre function can't be linked to MyGUI (undefined symbols).
As I think the reason of the errors is wrong linking order of the libraries.
So, I tried to move the order on the project struct, but nothing changed. It seems that changing order libraries in project struct doesn't change linking order. So how can i manage it?
I've seen the same question on OGRE forum.
But there is no answer :(

Related

Xcode linking against static and dynamic library

I have some problems with linking my macOS app against C libraries.
I have several question related to this issue.
It is better to link app against dynamic or static libraries taking into account that this will be very custom libraries rather not shared with other apps?
I have linked my macOS Xcode app against ~14 static libraries .a and it works fine. I have reconfigured CMakeLists.txt making this libraries and now Xcode project doesn't work. The main change was changing the directory I have
"$(SRCROOT)/../../c/<project_name>/outputs/lib/apple/static"
But now I have both static (.a) and dynamic (.dylib) libraries in the same path
"$(SRCROOT)/../../c/server/outputs/lib/apple"
I don't know whether this should matter, but linking against static libraries causes that after running my Xcode project it complains that it cannot load lib.dylib So maybe it finds this dynamic library under Library Search Paths and tires to load them but don't find them linked?
So I tired to link Xcode macOS app against .dylib libraries and instead of static .a libraries added them in Link Binary with Libraries. The problem is that the error not finding library now also occurs.
Maybe I should change something here ? But what If I will distribute my app to some other computers that will not have libraries in this specific location. How can I include dynamic libraries in Xcode bundle in order to be always findable.
I know I added maybe to many question. But would like to know how to the best solve this issue? Better to link statically or dynamically and then how to correctly achieve this avoiding this error.
UPDATE
It seems that when linking against .dylib it only works when I add path to this library directory to Runpath Search Paths.
It also seems that when I link against static library .a it works when .dylib isn't in the same directory (I moved .a library into /static subdirectory) and then for this moved library error isn't showing any more. But isn't there way to link statically when there is .a and .dylib libraries inside the same directory?
I know this is an old question but it's one of the top results when searching google for "Xcode static linking."
I recently encountered this issue when integrating with Intel IPP, which puts static and dynamic libs in the same directory.
If I used the standard Xcode linking method of adding the library via the "Build Phases | Link Binary with Libraries," Xcode translated that UI into a command line that looked like this:
clang++ ... -L/my/path -lstatic1 -lstatic2 ...
But that causes the linker to prefer the DLL instead of the static library in the same directory.
I worked around this by removing the entries from the "Build Phases | Link Binary with Libraries" window, and adding full relative paths to the libraries in the "Build Settings | Other linker flags" entry:
../../path/to/lib/libstatic1.a ../../path/to/lib/libstatic2.a
This caused Xcode to translate the UI into a command line that looked like this:
clang++ ... ../../path/to/lib/libstatic1.a ../../path/to/lib/libstatic1.a ...
Which linked the libraries statically.
Finally, I have linked this Xcode macOS project with multiple dynamic C libraries (.dylib).
REMARK
In order to link with static libraries (.a) They cannot be placed side by side with dynamic libraries! path/project_name/outputs/lib/apple/*.dylib and then place static libs under path: path/project_name/outputs/lib/apple/static/.a As XCode tries to link dynamic libraries if they found them on Libraries Search Path in Build Settings.
DYNAMIC C LIBRARIES LINKIN IN XCODE
Add dynamic libraries to Build Phases tab and Link Binaries with Libraries section as on the image
Embed all this dynamic libraries in output macOS Application Wrapper
You get something like this:
Then in Build setting add Libraries Search Paths
And finally add Runtime Search Paths in Build Settings

Qt c++ how to use nested libraries

Hi im rather new to qt here. Im using QT subdir to better organize and modulate my code.
I created a shared c++ library subproject (A) which uses the static gdal library. Then i created another shared c++ library subproject (B) which attempts to use (A).
Building (A) is okay. However the #includes for gdal dont work when i build (B). It says cannot open include file: 'ogr_feature.h': No such file or directory.
I went to read the qt guide in creating shared libraries and it said when deploying the library there should be no dependency to internal headers. What does that mean and how do i work around it?

Error building Static Library with OpenCV and Xcode on C++

I'm trying to build a DLL library for Unity3D (in 32-bit) but first of all I want to make a .a static library to make a C++ Wrapper for C#.
Well, this is what I've done.
I've built OpenCV unchecking BUILD_SHARED_LIBS in order to get the STATIC LIBS, with architecture i386.
I've made my static library code and built it, Linking the static libraries that I needed (I really import them all because I'm having errors and I want to know if it's an error lib-based):
(included from /lib/ and /3rdparty/lib/)
I'm linking my library and header in a new project (Command Line Tool) in order to test my new static library, but my errors are:
(pastebin link)
Well, I have no idea what's wrong.
This is my settings on the static library:
This is my settings on my test Command Line Tool (for testing my library)
Does anyone have idea about this?
Thank you very much in advance.
Regards.
EDIT: tried to manipulate the static libraries for 64 bits as well but nothing happened.
The solution was removing several paths on the Library paths since it was messing up some libraries.

Linking to a library that links to a library

I'm trying to link cpgui to my library, which links to SFML. I use code::blocks so I had to make my own project for that library, and as it requires SFML I statically linked to SFML in that library and compiled it fine.
Now, when I attempt to statically link that library to my library, I get a bunch of undefined references to SFML when I compile my project. Even if I linked to SFML in both projects, what's happening?
As you guessed, you can make it simpler by adding the library files directly to the project.
Another solution as suggested by AJG85 would have been to link the library -- after taking care of conflicting dependencies.
Use relevant documentation as suggested by answer to How do I link a library to my project in CodeBlocks & GCC without adding the library source to my project

Static library links in wxWidgets statically, but apps using my lib still require wxwidgets

Hopefully someone can help me out here.
I'm using Visual Studio 2005 and creating a static library that links in wxWidgets statically.
I have:
compiled wxWidgets statically according to their guide
included the lib directory in my "Additional Library Directories" property
added all of the wxWidget libs in my "Additional Dependencies" property
set my "Link Library Dependencies" property to "Yes"
set C++ Optimization to Disabled.
I know that some of those steps shouldn't have to be done, I did so on a "just in case" rational.
While my library compiles without a hitch, the test application that includes my static lib complains during linking that it cannot find 'wxbase28.lib' (which I included).
I should note that I abstracted wxWidgets out completely, so the library's public API has no mention of anything wxWidget-related. The test app shouldn't know that wxWidgets exists.
My tiny library has grown to over 51 MB, so I get the feeling that the libraries are being linked in... so why does my test application complain that it cannot find the wxWidgets library?
Thank you
It is the link step in the build process that pulls dependent libs in : When you build a static library, it does NOT pull in any recursive dependencies as there is no link step.
So both - your - and wx's - static libs need to be present then for the final application to link.
I hate to suggest the obvious, but is wxbase28.lib listed in the list of dependencies of your test application?