I have a .net core project and c++ project under same solution. When I build the solution or the c++ project, it outputs files .ilk, .exe.recepie, .obj etc files. I need it to ouput .dll file so that I can import it into my c# project. Can anyone tell me how to do that?
Also I don't want to change architecture of the c++ project to win32 because I use opencv in c++ project and if I use win32, it will not work and I feel it might run faster in x64.
I'm using Visual studio 2022, latest opencv, .net core 6
Related
Is there any way to build a Rust project with a C# .NET Core project when invoking dotnet build? The project structure is as follows:
<Root>
> Engine
Main.cs
> Native
> src
lib.rs
Cargo.toml
Root.sln
I am using P/Invoke to call the rust Native library from Engine, and I want a convenience step to build both the rust project and the c# project when dotnet build is invoked, including setup such as copying of the rust Native library into the output folder of the c# project etc.
Extra: If possible, is there any way to 'bundle' the Native library into the compiled c# Engine?
I built a class library as a NuGet package to be used in another C# project. When I built the class library, I followed a tutorial that suggested targeting .NET Standard 2.0.
I installed the package into the other project and it builds fine. However, I've noticed that the output folder contains several other 'System.' dlls (ie. System.AppContext.dll).
In the past, when I've built a class library for C++, I did not get the dependent dlls copied to the output folder. I had assumed that building a C# class library would act the same way. For C++, those dependent dlls are resolved at runtime by the C++ redistributable dlls. I thought the same would be true in that C# would resolve them through the installed framework.
So, I'm a bit confused as to why the extra dlls are present in the output folder. Is it because I targeted .NET Standard 2.0? Do I need to ship the extra dlls with my application?
I have created a C++ static library for ios (XCode 6.1) in visual studio. But when I compile this project, the output .a file is getting created in Mac machine and not getting copied back to Windows. My concern is that how can I refer this static library in an iOS C# application project in Visual studio?
So you have several options here, what you need to do is to have a Dll that contains the native .a library and the resources/code to interop with the native c++ library (and reference that Dll in your Visual Studio Xamarin.iOS project). You can use a Xamarin iOS Binding project as a container and one of the following options
You can use swig to wrap the c++ lib and there is actually a video from Xamarin University lighting lectures from Chris Van Wyk that describes the process.
You can use Mono CppSharp to wrap the library (My personal favourite easier to use than swig).
You can write your own c wrapper around the c++ library and P/Invoke that from C#
You can write your own Objective-C wrapper around the c++ library and use a Xamarin.iOS Binding project to interop with it.
Hope this helps.
As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project.
What are the pros and cons of both? Will they work cross platform (Android/iOS/WinPhone)?
To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
How do you add a uncompiled project to Unity3d?
Will they work Cross platform(Android/iOS/WinPhone)?
Yes. You can create a library project in Xamarin Studio/MonoDevelop/or Visual Studio. If you do not include platform-specific functions, it will be then cross platform.
To compile as DLL - Do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
See this tutorial.
Well Well Well too many question in a single post. Try to answer one by one:
Unity Offical Docs provide much help:
Question
As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project.
To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
Usually, scripts are kept in a project as source files and compiled by
Unity whenever the source changes. However, it is also possible to
compile a script to a dynamically linked library (DLL) using an
external compiler. The resulting DLL can then be added to the project
and the classes it contains can be attached to objects just like
normal scripts.
It is generally much easier to work with scripts than DLLs in Unity.
However, you may have access to third party Mono code which is
supplied in the form of a DLL. When developing your own code, you may
be able to use compilers not supported by Unity (F#, for example) by
compiling the code to a DLL and adding it to your Unity project. Also,
you may want to supply Unity code without the source (for an Asset
Store product, say) and a DLL is an easy way to do this.
More
What are the pros and cons
About dll:
Pros
You can build DLLs separately.
It could be faster to re-build one DLL
Cons
Calling code from DLL is slower
It would be slower to re-build hole project with all DLLs
Function names are visible. It is easier to reverse code that uses
dynamic DLLs
You can find more on here, here and specially on Google, our best friend:)
How do you add a uncompiled project to Unity3d?
Ans: What do you mean by uncompiled project? You mean scripts? then it is usually Copy\Paste inside asset folder simply.
When you open your Unity project in an IDE (for example Visual Studio), it is a solution with two projects, one for game scripts and one for editor scripts. You can add more projects to the solution through your IDE of choice. In order for this to work, you need to set projects target framework to one that is compatible with Unity (which uses a subset of Mono), for example Unity 3.5 .net full Base Class Libraries. Unfortunately .NET PCL is not supported.
You can reference your (or third party) library in any of the projects as usual, just remember it also has to be compatible with Unity.
Wether your code will work on all the platforms actually depends on what you use. On platform specific limitations refer to http://docs.unity3d.com/Manual/PlatformSpecific.html.
So i'm kind of new to programming but i started using Xamarin and i tried to add NHunspell package from NuGet on Xamarin Studio, it downloads it and the .dlls appear in Resources and NHunspell appear in Packets, but it doesn't appear in References and so when i try "using NHunspell" it doesn't work.
I have tried running the "install" script with Power Shell but apparently nothing changed.
How do I add NHunspell to my project?
Not every .NET library is compatible with Xamarin. They generally have to be either built against the appropriate Xamarin Framework, or build using a compatible PCL Profile.
scan.xamarin.com can tell you if a given DLL is compatible or not.
As I answered you already per Email the problem with NHunspell is that it is in fact an wrapper to Hunspell. Hunspell is written in c or C++ so it compiles to a native Dll. At this time the build produces two native DLLs for Windows 32 Bit and 64Bit. It would be necessary to produce native DLLs for ARM / Android or Linux or ... to use it on these platforms. I will do this for X86/X64 Linux in the future. But at the moment I'm snowed under so there is no timeframe. If you or someone else is willing to contribute, you're welcome.
BTW. NHunspell has an resolver for the correct native DLL. If your project has the native DLLs in the output directory, it resolves X86 or x64 in windows. You can do this in Xamarin studio by adding the native DLLs in your project and configure "copy to output directory". But this works only in Windows.
The latest packages (without NuGet) are here:
http://download.crawler-lib.net/NHunspell/