I need to feed data to Dafny functions and get their output. For that, I am trying to create a C# program that calls the Dafny functions.
As a test I created a very simple Dafny file:
module myDafnyModule {
method boolMethod(b: bool) returns (r:bool) {
return !b;
}
function method boolFunctionMethod(b:bool):bool {
!b
}
}
My main guess is that I should approach this as a multi-file .NET assembly.
For this, I should
generate the C# for the Dafny part of the program with something like dafny /spillTargetCode:1 dafnyModule.dfy
compile that as a module with something like csc /target:module dafnyModule.cs
compile the main C# program with something like csc Main.cs /addmodule:dafnyModule.netmodule.
Step 1 works. However, the csc call in step 2 fails with lots of errors like
$ csc dafnyModule.cs
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.
dafnyModule.cs(50,28): error CS0234: The type or namespace name 'Immutable' does not exist in the namespace 'System.Collections' (are you missing an assembly reference?)
dafnyModule.cs(1718,40): error CS0246: The type or namespace name 'BigInteger' could not be found (are you missing a using directive or an assembly reference?)
...
My questions are:
What is missing in the csc call in step 2 to compile the C# code generated by Dafny?
Is this the best way to interface with Dafny code? There are other options I could imagine, though they seem more laborious and error-prone:
have the main entry point in Dafny and have it call C# functions to deal with the input/output?
have a C# program load at runtime the DLL generated by the Dafny compiler?
Actually, I'm not a C# person and I'd prefer to call into Dafny from Java! But I guess Java support is less mature than C# and there's less information. A Java similar question got no answers...
For completeness, I am using Dafny 3.1, dotnet 5.0.104, csc from mono 6.12.0.90 on macOS 11.3.1.
I realized that the Dafny-generated C# code starts with a handful of lines that seem to hint to use dotnet to compile, instead of csc (which I was using because dafny /help mentions it).
Following that thread I found how to build an application with a library using dotnet.
And it worked, just by putting the generated C# code where the library is expected and the main app where it should be.
The whole solution & project thing of dotnet sounds kinda daunting and brings painful flashbacks of Visual Studio on Windows, but it was mercifully straightforward.
Related
I've looked over a few questions with a title just like this one, but they either do not talk about command line, or don't seem to work for me for some reason. From what I have read, it seemed as if I could "simply" do the following:
The dummy code (C#):
using System;
public static class Foo {
public static void Bar() {
Console.WriteLine("o3o");
}
}
More dummy code (Visual C++):
#using <test.dll>
int main() {
Foo::Bar();
return 0;
}
C# DLL compiled using:
csc /out:test.dll /t:library src\cs\Foo.cs
Visual C++ object file compiled using:
cl /Ox /clr /AI. /c src\vc\test.cpp
Executable compiled using:
link /out:test.exe test.obj
The following exception is thrown upon running the executable:
Unhandled Exception: System.TypeLoadException: Could not load type 'Foo' from assembly 'test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at main()
at mainCRTStartup()
I have a strong feeling that I was supposed to also reference the DLL in the link phase, but I couldn't find any option for linking a DLL similar to GCC's -l option. Attempting to pass the DLL along with the .obj to link causes it to tell me that linking assemblies is not supported. Interestingly, though, if I build a .netmodule instead of a DLL, i.e. by:
csc /out:test.dll /t:module src\cs\Foo.cs
and changing the #using directive to
#using <test.netmodule>
the executable runs without error. This feels a bit weird, for I don't think anybody packages code in .netmodules (what are .netmodules, anyway?).
All of your steps should have worked, but one very simple issue is preventing your program from running.
Namely: Your C# DLL assembly name is test, and your C++/CLI exe assembly has the same name. They both have the same identity.
So when looking for Foo::Bar in the test assembly, the loader first checks if the assembly is loaded in the AppDomain. It is - it's your C++/CLI exe, and you can't have several assemblies with the same identity loaded simultaneously within the same AppDomain. Your C# dll wasn't even given a try.
Just change either one of them and everything will work fine:
link /out:test2.exe test.obj
As for what's a .netmodule, it's the format used for linking managed code statically, that's why you managed to link your C# code with your C++/CLI code without issues. It's roughly the equivalent of a .lib file for managed code.
And you're right, it's not used very often.
I'm attempting to use the following command line command to compile an assembly of the code from my project:
C:/"Program Files"/Unity/Editor/Data/Mono/bin/gmcs
-target:library -out:C:/Users/Austin/Desktop/PixelExpanse.dll
-recurse:C:/Users/Austin/Desktop/Projects/Repos/trunk/PixelExpanse/SpaceColonyRefactor/Assets/Source/*.cs
-d:RUNTIME -r:C:/"Program Files"/Unity/Editor/Data/Managed/UnityEngine.dll
As you can see, I am, I believe, correctly referencing the UnityEngine.dll.
The code that would be compiled contains references to UnityEngine.UI and UnityEngine.EventSystems. But when I run the above command, I get the following compile error:
error CS0234: The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine'. Are you missing an assembly reference?
From what I have been able to find through googling, it SEEMS like an error people were getting when using a pre-4.6 assembly, because thats when EventSystems and UI were both introduced. But I don't know how I could be missing that in the dll I'm referencing as Unity 5 is the only version that has ever touched this computer.
As a side note, I have posted this question to Unity Answers and have yet to receive a response. I expect it's because assembly compilation is beyond the scope of what most users there choose to undertake. Hence my asking it here.
The namespace UnityEngine.EventSystems actually appears in UnityEngine.UI.dll and not UnityEngine.dll so it seems you need to reference the former too when compiling manually from the command-line. Unity projects have this by default (see below).
This is verified by opening up the assembly in your reflector tool of choice, here I am using JetBrains dotPeek:
This is how my test project appears with default Unity references. Note that by default a reference to UnityEngine.UI already appears in the Unity-created project:
When I built my Windnows desktop app via Unity, the above dlls appeared in:
<drive>:<projectOutFolder>\<projectName>_Data\Managed
You can try:
right click on "project panel", and after "Reimport All".
It's can be happen due to switch between platforms, e.g. IOS, or Desktop.. thus, folrders are deleted by became unecessary..
Solve for me: Unity 5.2, Win 7, 32bits;
Good luck!
I checked the UnityEngine.dll and the Eventsystems/UI namespace is not included. Despite, there is a dll in Unity5\Editor\Data\UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll which includes these namespaces.
For mac, it's /Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll.
I am still learning c# and have been following a tutorial where I use Visual Studio to connect MySQL. I want to compile the file using csc on the command line this time and error cs0246 came out6 where its ays "The type or namespace name 'MySqlConnection' could not be found (are you missing a using directive or assembly reference?)".
I am just using the command "csc MyFile.cs". I know that I should be using some form of directive but I'm not sure how to use it? In Visual Studio, all I have to do is add the MySql.Data and MySql.Data.Entity into the Reference under the project. How do I use the csc command?
csc /? contains all answers... Also covered in Working with the C# 2.0 Command Line Compiler.
Will be something like (not sure what is the name/path of assembly you need to link):
csc /reference:MySqlConnection.dll MyFile.cs
I am trying to run a C# console application on my server which is running Ubuntu Server 12.04. I have installed Mono JIT version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2) and additional packages like gmcs and MonoDevelop. The file that I am trying to execute is called Program.cs and when I run the command $gmcs Program.cs I get the following errors:
error CS0234: The type or namspace name 'Tasks' does not exist in the namespace 'system.Threading'. Are you missing assembly reference?
error CS0246: The type or namespace name 'MySql' could not be found. Are you missing a using directive or an assembly reference?
error CS0246: The type or namespace name 'MySqlConnection' could not be found. Are you missing a using directive or an assembly reference?
I have researched into referencing the .dll files for the above namespaces but have not been able to find an answer that is clear. Most forum links suggest that I install mono - trunk, but I want to know if I should uninstall the existing mono package and then install mono-trunk.
I am new to the Unix platform and researching every step of my way. Your help will be much appreciated.
If you are compiling from the command line, you will need to pass the referenced assemblies as a series of /r or /pkg switches, such as:
mcs /r:MySql.Data.dll Program.cs
Obviously you will need to have the required assemblies installed too.
Also note that gmcs is an (old) alias for the .net 2.0 compiler, that's why it doesn't see System.Threading.Tasks (which is a .net 4 feature). See the -sdk switch of mcs.
You should probably install monodevelop to have a user-friendly IDE to help you.
I am pretty new to mono and C# so this is probably a simple question, but i cannot find the answer.
I need to compile a C# visual studio console application on my mac. I thought mono would be right for that purpose. I don't know which file to compile and took program.cs (where my main function is) or should i compile Project.csproj.
When i run
gmcs Program.cs
I get
Program.cs(17,16): error CS0246: The type or namespace name `Oplossing' could not be found. Are you missing an assembly reference?
Program.cs(129,54): error CS0246: The type or namespace name `Order' could not be found. Are you missing an assembly reference?
What en how should i compile?
Via xbuild, you should be able to compile csproj directly,
http://www.mono-project.com/Microsoft.Build
Unless you are working on a system without a ui, (since you are targetting macos you have a ui) download and install Monodevelop and open the visual studio project with that.
Otherwise check the (g) mcs documentation
The way to use it is already in te comments here
Note: you do NOT have to recompile your app on MacOs to run it on MacOS, just copy the exe (assembly) to your mac and execute it with mono