Build Cocoa application Bundle with private dylib/framework - objective-c

I use xcode 4 to build a cocoa application with a private dylib/framework.
In my development Mac, I put the dylib in the /usr/local/lib directory, and drag it into the project.
The app is compiled and runs perfect on my computer.
To distribute this app to the other Mac, I create a copy Files building phase, and say "copy that dylib to Frameworks directory".
The application is built successfully, and I indeed see the dylib is copied to the Frameworks directory in the app bundle.
The problem is when I run this app in another regular Mac, which does not have this dylib installed. I get an error saying:
dyld: Library not loaded: /usr/local/lib/mylib.dylib

The issue comes from the fact that you copy the framework into the app bundle, so it is available at a location like:
<you_app_path>/Contents/Frameworks
but you try to load it from /usr/local/lib where it is not available on you deployment machine. From Apple Framework Programming Guide:
To embed a framework in an application, there are several steps you must take:
You must configure the build phases of your application target to put the framework in the correct location.
You must configure the framework target’s installation directory, which tells the framework where it will live.
You must configure the application target so that it references the framework in its installation directory.
Now, you say that the build phase is ok; I assume also that you sent the application target build setting correctly. What is left is configuring the framework target’s installation directory.
If you did not build the framework yourself, you should be able to fix this by changing the framework install path so that it is defined relative to the loader (your app), to something like: #loader_path/../Frameworks/ (or #executable_path/../Frameworks). You can do that by means of install_name_tool.
If you are compiling on your own the private framework, you can define its install location in Xcode build settings.

Related

Can't load external DLLs from MSIX packed application

What works in normal desktop application
When we try to load a dll from a normal desktop application the system automatically checks the directories specified in the environment variable "PATH" and finally, the dll is found. E.g. we are using NVidia CUDA dlls this way.
What doesn't work when application is packed into MSIX?
When we pack this application into MSIX the dlls can't be found any more, because the packed application doesn't check the folders specified in the environment variable "PATH".
In some cases a workaround would be to load the dll dynamically from code, but it only works when the dll has no dependencies. Otherwise the loaded dll is not able to find it's dependecies.
What's the recommended approach to load the dlls to which path is defined in environment variable "path" from MSIX packed application?
Platform: Windows 10/11
Language: .NET/C#
How do you know the DLLs are not found when packaged as MSIX? Are you debugging the app with Visual Studio or using Process Monitor?
From what I know an application packaged as MSIX should still be able to load resources from folders listed under PATH env var. An MSIX package cannot write in the PATH env var, but the application it installs should be able to read it.
A known problem with loading DLLs from MSIX packages is when the DLLs are in a different folder from the one where the EXE loading is found. But this applies only to DLLs that you deploy inside your package, not DLLs installed by other applications on the machine.
The role of the MSIX container is to isolate the resources from the MSIX package (restrict other applications from accessing them), but the application deployed via an MSIX should be able to "see" all the resources present on the machine (installed by other non-MSIX packages), just like any other application.

ASP.NET 5 and Build Action

I have a Web Site and Class Library built with ASP.NET 5. The Class Library depends on an set of external files (XML, EXEs, etc.). Those dependencies are added as part of the project and visible in the Solution Explorer of Visual Studio.
My Web Site has a dependency on the Class Library. When I build the Web Site, I would expect the dependencies of the Class Library to be copied to the Web Site, but they aren't.
The Build Action (Copy always, Copy if changed) appears to be gone with ASP.NET 5. How do I make sure that dependencies other then the DLL of the Class Library itself gets copied to the Web Site project?
First thing first, they won't be in src/yourProject/bin/Debug. Those have been moved to the artifacts folder.
Also, your project by default will not output DLLs. This is mainly due to performance reason but if you need your DLL to publish your application, check your project properties. In the Build section you should have an option called Produce outputs on build. Tick that and bingo.
You have your dlls. Most of the time (aka: while coding), you won't need them since they will always be recompiled in memory.
You need to manually add a pre/post build step in project.json

From where is the worklight folder inside the wlapp file copied from when we perform a Mobilefirst build?

I just wanted to know how the worklight folder is compiled and copied inside the wlapp file. I am referring to the worklight folder which consists of the cordova plugins folder, worklight.js, cordova_plugins.js, etc.
These files are used during build-time by the Worklight Build Engine. They are located in the TMPDIR of your OS. Since you're using OS X you can open Terminal and run the command open $TMPDIR/wlBuildResources (> your-WL-version\jslibexpanded).
I am guessing you are asking this because you are thinking of altering these files pre-build time? You must not do that as it may generate a faulty application (it does not go only to the wlapp file but also to the generated native project of any mobile environment you may have added to your application).
These resources are also deleted and re-created on each launch of Eclipse (with Worklight Studio installed).
This will of course also void any support requests.
Since this is probably related to your other question about using the Ionic Keyboard Cordova plug-in, note that in the upcoming MobileFirst Platform Foundation 7.1 there is Cordova application support, enabling you to create either an iOS or Android application with MPF as a plug-in like any other, thus you can also leverage any Cordova plug-in that you would like. More on this, soon, once 7.1 is released.

Compile ansi c vendor library with objective-c

I'm using ObjC to build my app's ui, and my app depends on an ansi c library, I have the ansi c library's source code. How can I use Xcode to compile this app (For development, I can install the library into my Mac). But I want to ship my app to users without any external dependency, just like any other apps, user don't need to install the dependencies, so how can I accomplish this?
If you have static library then add the same to your Xcode project and compile application. During linking phase library is linked with Application binary and hence no separate installation required for the library.
In case library is dynamic library then check the installation path. If the library installation directory is outside application bundle then you need to create installer to install library to installation directory. On the other hand if installation directory is relative to #excutable path then you can keep the library inside your application bundle and no installation required. You can use copy file phase to copy library into your application bundle.Refer Apple documentation

Copying dynamic library (.dylib) into a framework (.framework)

I have two XCode projects: a framework and a client application.
My application depends on my framework and everything works fine with that — the framework is being recompiled everytime the app is, the projects build paths are set correctly, it's completely okay.
Now the framework started using 3rd party dylib file, and it's linked against the dylib.
I've even added a build phase to copy that library into the framework's resources dir.
When i'm trying to run the application, everything compiles correctly, then i get this:
dyld: Library not loaded: /usr/local/lib/libplplot.9.dylib
Referenced from: /Users/railsmaniac/Projects/Study/Calculus of >approximations/Builds/Debug/XNMaths.framework/Versions/A/XNMaths
Reason: image not found
How can i fix it?
Adding the library into client application's resources doesn't fix the problem.
I can just place the library into the required location, but i prefer to keep it IN the framework.
Is it possible?
It looks like your application is expecting the library to be found at a specific path on the system. If you are on OS 10.5+ you can use the new #rpath functionality to allow your application to link dynamically to your library.
See this post for further details. It also shows the "old" way of doing this.