Problem loading Assemblies in MonoTouch Project - xamarin.ios

I am building a Monotouch (trial) 4.0.3. project. It compiles with the warning:
Warning: Library 'loader.dll' missing in app bundle, cannot extract content
All of the other dlls are successfully bundled during build, and this one was working before. After compiling with the warning, it crashes on load at runtime (on the simulator) with a segmentation fault when it fails to load the assembly.
I have searched for this warning and I haven't been able to find any references to it.
Does anyone know why the assembly is not being added to the app package?

It sounds like the linker is removing the loader.dll because it thinks nothing uses it. Try setting the project's linker setting to "link sdk only".

mhutch is correct, the linker is opportunistically pruning out the library. However, the default linker setting is not to link anything, so his solution will only work in the rare case that you're linking all assemblies (which you don't want to do with MonoTouch because references to the SDK should never be embedded).
The workaround is to just new up an instance of something in the library you want to use, from inside the calling assembly.
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MyLibrary;
namespace MyApp
{
public class Application
{
static void Main(string [] args)
{
new MyLibrary.DontPruneMeBro();
UIApplication.Main(args, null, "AppDelegate");
}
}
}
As an aside, I don't know what iOS developers do, since this behavior would make run-time access to satellite libraries impossible.

Related

Xamarin.ios using DLL library

I have xamarin binding project (represents kind of bridge to native iOS static library) which works fine if added to a solution.
What I'm trying to do is to use /bin/libary.dll instead of binding project.
I created new xamarin.ios simple view project, added reference to library.dll.
Project compiles fine using API from that library but when run i'm getting fatal error:
so there is no even entry point to application
sorry probably for posting obvioues answer, but I need to get it working fast.

Android Studio -- linking with a .aar that contains a .so

I'm migrating an existing, working project from Eclipse to Android Studio. The code base consists of a native C++ library built with the NDK (libMylib.so), a Java class that wraps all the native code (MyClass.java), and a test harness(MyApp).
In Android Studio, I've created a stand-alone project (not just a module) that builds "MyClass", and that project has a "src/main/jniLibs" folder where I place "libMyLibrary.so".
The project builds and produces "MyClass.aar", which contains all of its dependencies -- including those .so files.
My test app imports this .aar file as a new dependency "module". It builds and deploys to a device, but encounters a runtime exception when trying to call a native method contained in the .so file.
Trying to load lib /data/data/com.mycompany.webview/lib/libMylib.so 0x4131cd18
Added shared lib /data/data/com.mycompany.webview/lib/libMylib.so 0x4131cd18
nativeCalls.cpp﹕ JNI_OnLoad() called successfully.
No implementation found for native Lcom/mycompany/Mylib/MyClass;.nativeInit
Shutting down VM
The debug statement printed in "JNI_OnLoad()" is mine, so I know the correct .so is being loaded without issue. But then something goes wrong with the call to 'nativeInit()'.
What sorts of things could cause this kind of failure?
Thanks.
1) What value does JNI_OnLoad() return? In the code that I have it is JNI_VERSION_1_6.
2) Are the function names correct?
cd bin/classes
javah com.example.MyClass com.example.OneMoreClass
This will generate the correct C/C++ headers for your native functions.

Creating console MonoMac application

I need to create a console MonoMac application.
Open Xamarin Studio and create C# console application project (not MonoMac specific).
Add reference to MonoMac assembly.
Edit Main method in Program.cs:
using System;
using MonoMac.Foundation;
namespace ConsoleTest
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine(new NSString("Hello World!"));
}
}
}
The project builds ok. But when I run it the console opens with error:
Missing method .ctor in assembly /.../ConsoleTest.exe, type MonoMac.Foundation.NSString
So the console project runs on Mac, but MonoMac assembly cannot be used. How to fix it?
Solved.
MonoMac should be compiled from sources:
Clone https://github.com/mono/monomac (including submodules).
Open terminal and run "make" in the root folder.
Find MonoMac.dll in src folder and copy it to your project directory.
Reference it directly (don't use the version bundled with Xamarin Studio).
One thing I also tried is to run NSApplication.Init() when starting the app. It seems a working solution too.

Visual Studio 2010 C++/CLI in Static Library Mode: could not find assembly 'mscorlib.dll'

I am working on a C++/CLI project with VS 2012 in Dynamic Library (.dll) and x64 mode.
If I switch the mode to Static Library, I get the error below.
Error 1 error C1107: could not find assembly 'mscorlib.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable C:\Depot\Main\Current\Sln\ALibraryProject\Stdafx.cpp 1 1 ALibraryProject
I tried removing the reference to the mscorlib.dll then adding it again from:
Project > Properties > General > Common Properties
But that didn't help. As I know that VS handles the reference to the .NET assemblies, I don't want to add a disk file reference to it as it seems illogical! Did anybody face this before?
I had the same problem when converting my solution from the VS2010 compiler to VS2013 compiler.
I resolved it by changing the project settings (for the project containing the managed .cpp file that was throwing this error) as follows: In Project Settings | C/C++ | General | Additional #using Directories I added the macro $(FrameworkPathOverride). This resolves to the reference assembly directory for the version of .NET that you're targeting, which in my case is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1
If I switch the mode to Static Library
This is not the typical error you get when you try to build a static library with /clr in effect. I'd have to assume you've been tinkering with project settings to get rid of the inscrutable linker errors you get when you try to do this.
Core issue is that the C++/CLI build system doesn't support static libraries that contain MSIL. Managed code doesn't use a linker, binding happens at runtime. Which makes the essential difference between static libraries and DLLs disappear. So Microsoft decided to not support it because it didn't make much sense to implement it. Unfortunately they don't yell loud enough when you try to do it anyway, the linker errors you get don't give enough of a hint what you did wrong. Workarounds, like merging with ILMerge don't work either, it cannot deal with mixed-mode assemblies. Merging the native code sections and their associated relocation table entries is very untrivial.
Keep in mind that it is fine to link native static libraries. A typical C++/CLI project has only the ref class wrappers that need to be built with /clr in effect. You can glue any amount of native code from libraries into the final assembly.
I'm forced to theorize about the actual compile error, too many programmers get this error for another reason that doesn't have anything to do with building static libraries and they are harassing me in the comments.
Do beware that targeting a different version of .NET than the one you have installed on your machine is quite a hazardous affair, particularly so if you want to target 4.0 and you have 4.5.x installed. The key element in your .vcxproj file is the <TargetFrameworkVersion>. This will be missing if you started the project targeting an old .NET version, you have to insert it yourself. The IDE also doesn't support changing it if it is present, again edit by hand.
Which is enough to coax MSBuild into generating the proper compile command. You can verify if that panned-out well, look in the *.tlog subdirectory of the Debug build directory for your project. The cl.command.1.tlog file shows the options that were passed to the compiler. It should contain:
/AI"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0"
/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll"
Note the subdirectory, very important that it matches your intended .NET target. v4.0 in this example. And very, very important that it does not point to c:\windows\microsoft.net, the legacy location for reference assemblies.
I have the same problem. Having a dll doesn't work, as I need to provide a native C++ wrapper for a .net object so it can fulfil a natice c++ interface - I can't use .net in a dll interface - this gives a compile error
This worked as a static library in VS 2010 (with .net 4)
Some of my executables and dlls which also have some code with /clr. They don't have an issue. I'm not trying to make a net Lbirary.
I solved it by removing dependency in old and not updated mixed lib, which was also configured only in Debug configuration, and as result, it started to get the same error as yours after I changed some code.
It was not simple to find it, because error is not clear, and the dependency was set up via "Additional Dependencies" in project settings.
Open visual studio and unload your project then Go to the project folder and open file .vcxproj . Search for tag "targetFrameworkVersion"
(if not present it means ur project is not using dot net frameworks.so no requirement of change)
Change it to required version
Save the file.
And now reload the project .

just statically linking to libboost_thread triggers access violation crash on startup

I am dealing with the following setup:
A C++/CLI dll links to a static lib, which itself links against a static build of libboost_thread.
Without linking against libboost_thread the .exe, that loads the dll, runs fine.
I can even link to libboost_system and it still all runs fine.
At the very moment that I am linking against libboost_thread, the application always crashes with an access violation on startup before even entering any of my code.
This even happens if I am not including any boost header, I don't have to use anything from boost. Just linking against boosts threading library is enough to let the app crash.
I am using boost 1.53.0 and the prebuilt windows libs from http://boost.teeks99.com/ (especially libboost_thread-vc110-mt-gd-1_53.lib in both,the 32 and the 64bit version, tirggers this issue).
Any idea, what can cause that?

Resources