I am using Xcode 9 to build a project that requires linking against a large number of standalone libraries (.a and .dylib files), which are all located in an arbitrary directory outside of my project.
I can build if I manually add all these libraries to Linked Frameworks and Libraries, but then I am hardcoding a relative path to this arbitrary directory.
Is there a way to add libraries to Linked Frameworks and Libraries list, but add them as paths relative to a user-defined location, perhaps a location specified as a User-Defined Build Setting?
To be specific, I have an environmental variable G3D which specifies a path. All these libraries are off of $G3D/build/libraries. But after adding the libraries to my project by dragging and dropping them, the File Inspector only lets me specify their location as being Relative to Group, Relative to Workspace, etc..
It’s possible to specify libraries relative to an arbitrary variable if I opt out of the Linked Frameworks list entirely, and specify all the link libraries using the Other Linked Flags Build Setting, but that introduces its own problems.
Well, in your Framework Search Paths in build settings, you are allowed to refer to your user-defined build setting... e.g. say you have a user-defined build setting REALM_PATH which specifies some portion of a path.
Then in your Framework Search Paths build setting, you can add some path and insert REALM_PATH by putting ${} around it. E.g.
${PROJECT_DIR}/../../External/ThirdParty/submodules/${REALM_PATH}
Related
Below is a picture I grabbed off google, and it is actually linked back to a previous Stackoverflow question.
So, on the left (project explorer view) we see an Includes and src directory. I believe the Includes really is just paths to where header files may reside in the file system.
So now for my question, should header files I have made say "xyz.h" reside in the src folder in an Eclipse project?
Currently I put them somewhere in the file system on my Linux machine and then path to them (so they show up in the "Includes" for the project), this allows me to edit them in the eclipse editor and so forth, but I believe they are not actually a part of the "Eclipse project".
Not sure there is a right and wrong answer, just looking for what others few as the "best" way.
Generally the header files that you create should be in your project.
The main purpose of the "Includes" mechanism is finding the headers of third-party libraries that your project may use.
You can also use it to specify the location of includes inside your project. For example, you might have an include folder inside your project, put all (or some) of your headers there, and configure that as an include path. Eclipse allows you to configure include paths relative to the project, by choosing "Project Path" when adding the include in the project's Paths and Symbols preference page.
As your projects get large, you may eventually want to split them up into several projects, such as an application and supporting libraries. In a case like that, the application's project would have include paths pointing to the headers in the library projects.
I created a new project for compiling a static library (e.g.: libmyproduct.a) for MacOSX.
As seen in the second screenshot, I need to specify the header path for the project (for example, path for the boost header files), but I don't see any option in the IDE! Usually, there is an option such as header-path for me to add a path to. Without specifying a header-path, there is no chance I'll ever be able to compile my source code.
You can specify the same by switching to the All tab in the target Build Settings and looking for Header Search Paths
I am trying to compile an app that uses multiple libraries using Xcode. To do so, I created a script that copies all of my .dylibs from a location on my computer to the Frameworks folder inside my app bundle.
After adding the necessary linker flags and header search paths, I must now add my library search paths.
Since I have copied all the libraries inside my Frameworks folder of my app bundle, I have deduced that I must add $(FRAMEWORKS_FOLDER_PATH) to the library search paths setting. Adding this fails, because the linker can not find that directory.
I am guessing that the Frameworks folder isn't created until after searching the library search paths setting. If so, how am I supposed to use the libraries that I have copied inside my app bundle?
Placing the .dylib files in the Frameworks folder is something you do so that the application can find them when it runs.. dylib files are dynamically linked, so the application loads them at run time.
Setting Xcode up to link to the .dylibs at compile time should just be a matter of dragging the .dylib from the Finder into your Xcode project. I've shown this with a simple example project that uses libxar.dylib in the attached screenshot.
I don't fully understand when to use a workspace.
Here is what I have been doing so far --> Whenever I need to use a static library of another project, I drag the .xcodeproj file from finder to the Xcode navigator of my new project, link the libraries, add the user paths, and start working. I also add the appropriate target dependencies.
Why is using a workspace better? Should I be using a workspace? I have tried understanding apple's documentation, but I seem to be getting whatever I need without explicitly creating a workspace.
Here's what I found so far, it makes using static libraries easier. If you add the path to the static libraries xcodeproj file in your source tree, and specify the path in the build settings user header paths, and set Always search header paths to "YES". Then you're set. All you need to do is link to the static library in your build phase. Code completion works.
I have a directory of source files (.h and .m) that are shared between multiple projects. I'm not building them as a static library; instead, I just include the source in each project.
Previously, I was copying the source into each project independently, but now, I'd like to move to having a single directory that has all of those shared files it, and include a folder reference to them in each XCode project that uses them.
Including them as a folder reference (blue folder) is no problem, and I can add the path to the header includes so that the files in the project can see them. But they're not being built, and thus I'm getting link errors.
How do I get Xcode to build the source in the external directory?
folder references don't work like that in xcode.
this is exactly what an external target (e.g. static library) is for... seems strange that you would choose to duplicate (a portion of) the maintenance for every project. with a library, you can also reduce the build and indexing times (assuming the build settings match some of the time).
if you insist that a static library is a bad idea... you can approximate what you want by creating a custom build script phase for your target (you will need to configure a script, rather than passing the xcode folder reference as input).