How do I use Clang from a C# project? - c#

My goal is to use Clang within a C# program to parse C++ source code and build an AST.
If I understand correctly, I need to get libClang from somewhere as it is a C wrapper around Clang, and then I should be able to use the code in the following link to be able to use libClang from a C# project.
https://github.com/SimonRichards/clang-sharp
My problem is I am lost on how to install Clang. I have download the source from here:
https://github.com/FunkMonkey/libClang
and I tried running the makefiles through the visual studio command prompt but it just gives me an error:
Makefile(14) : fatal error U1034: syntax error : separator missing
Stop.
I'm quite confused as I'm not used to github and makefiles. I think the general process I need to follow is:
Install LLVM - where and what is this?
Install Clang - where is this?
Install libClang - how to run the makefiles?
Use SimonRichard's clang-sharp

I was unable to use the project listed here, however, I was able to get up and running using http://www.nuget.org/packages/ClangSharp

There are plenty of documentation how one can get started to use LLVM / Clang. And all this documentation is pretty explicitly mentioned on the websites:
http://llvm.org/docs/GettingStarted.html
http://llvm.org/docs/CMake.html
http://clang.llvm.org/get_started.html
And bunch of stuff around.

Related

Xamarin iOS native linking failed for grpc.core

I've been attempting to make grpc work (ssl http2) on Xamarin Forms and after some pain I managed to get it to work on Android using Grpc.Core. However I couldn't get iOS to compile. Working through this problem I was trying to get anything grpc related to work on iOS, and eventually found the grpc experimental xamarin demo, HelloworldXamarin. Found here:
https://github.com/grpc/grpc/tree/master/examples/csharp/HelloworldXamarin
I downloaded the solution, but when I try to compile it I get the following errors:
Error Text:
Native linking failed, undefined symbol: operator delete(void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Native linking failed. Please review the build log and the user flags provided to gcc: -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc_csharp_ext -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc_csharp_ext.a -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc.a
linker command failed with exit code 1 (use -v to see invocation)
For the warning regarding not being able to find libgrpc_csharp_ext.a, I verified that the file was there.
There appears to be some issue with native linking, which I am very unfamiliar with. I'm using nearly the latest Visual Studio (well, 16.5.3), a mac build host with latest OS and XCode updated to latest. Didn't make any changes to the files pulled from git. I only just started working with Xamarin iOS this week, so everything should be in a fairly "default" state.
What could be wrong with my setup/system that makes this not work? I understand that this is an experimental feature still, but I can't tell if I've done something stupid or if there's been some change in something (like XCode? or it needing VS 2017?) that makes this no longer work? Is anyone else able to get this example to compile?
I've also tried newer versions of the grpc nuget packages and that only resulted in more errors.
Ultimately I'm trying to get latest Grpc.Core to work in iOS on Xamarin.Forms, though I have very little experience working with iOS. If there are issues with the latest versions of XCode/Visual Studio/Grpc.Core that are causing this, I'm willing to try to work through them, if someone can point me in the right direction.
It is not at all related to your versions or something that you did or didn't do.
First for some theory:
If someone wants to use Objective-C libraries or CocoaPods packages in their Xamarin project, they will need to create a binding library for this. Take it as some sort of a "bridge" between the native implementation and the later exposed C# code that you can use. You can learn more about the binding from the official documentation here and more specifically here.
To sum up the info - after the bindings have been created, you see a .lib or .a file. This is exactly what they have done - exposed some native code into the libgrpc_csharp_ext.a. Unfortunately, there are some bindings that are not correct. This is exactly what you are seeing here - the aftermath of an incorrect binding.
Looking a bit into the project I got to the following conclusions:
There is an open issue from May 2019 about this - https://github.com/grpc/grpc/issues/19172
Unfortunately, the issue is still active and there is no movement there.
I have confirmed that after version 1.21 (incl.) the build is not working. For now, you can downgrade to version 1.20.1 (last known to work). I have successfully built the solution with it. Please review the changelog and release notes for this specific version (if any) so that you know if it will fit your needs.
Basically, you have 2 options:
Downgrade to the last good version in order to use it;
If you want to use the latest version either wait for the issue to be fixed, or fork the repo and help with the fixing.
If you want to see their build script and help fix the issue, you can start from here.
Another useful resource is this video from the official Xamarin channel.

Using RoundhousE with dll File

I've decided to use RoundhousE for my database. Now there are three ways to use this tool. With MSBuild, a DLL File or the console application. I found some documentations how to use the MSBuild variant and I know how to use the console application but I can not find anything how to use the DLL in Visual Studio and how to call/configure RoundhousE this way.
Does someone know where to find a detailled documentation or could someone explain me this?
The DLL is used in a few places, like with DropkicK - it may not be a bad idea to explore how it uses it, as there is not much documentation with this otherwise. You can also review how Roundhouse RefreshDatabase uses it as well.
DropkicK - https://github.com/chucknorris/dropkick/blob/master/product/dropkick/Tasks/RoundhousE/RoundhousEClientApi.cs
RoundhousE-EntityFramework RefreshDatabase - https://github.com/chucknorris/roundhouse-entityframework
HTH

Running different makefiles in windows

I've downloaded Apache Thrift and have created a thrift file that nicely generates code (I'm using csharp). I've now got to the stage of including Thrift in my Visual Studio project (I'm using 2013 version) and am stuck on how to do this.
Thrift includes all the source files I need but just copying them to Visual Studio creates a load of errors. I noticed that there are several makefiles that come with the source: There's a Makefile.am and a Makefile.in. I tried running:
nmake -f Makefile.am
nmake -f Makefile.in
but i keep getting syntax errors.
Any help would be much appreciated.
Here are the syntax errors:
Makefile.am(73) : fatal error U1034: syntax error : separator missing
Stop.
and:
Makefile.in(16) : fatal error U1035: syntax error : expected ':' or '=' separator
Stop.
As you can see the errors are just basic syntax one's.
Still a good idea to post the source and the error messages. We don't like guesswork, because it is highly inefficient. And you want quick help, don't you?
The help I need is what to do with all the different types of makefiles.
First, I'm not sure why you need a makefile at all. You could easily achieve he same result by calling Thrift in the prebuild step. I do that via batch files, which gives me enough control over the process. But, yes, you could of course also call nmake -f makefile here, but note there is no extension after makefile.
In a nutshell and without spending too much time on details, the makefile.am and makefile.in are typically GNU automake files. Roughly, during bootstrap.sh && configure these makefile.am files are converted into makefile.in files and finally into makefile files, which then are to be consumed by make or equivalent tools.
But honestly, on Windows platforms, GNU automake is something that I would consider the option of last resort - if there is any other option available, choose that one.
Last not least, the tutorial, library and test *.csproj files show at least one way how to integrate Thrift in the prebuild step.

ANTLR C# Can't find 'IAstRuleReturnScope'

I have downloaded the csharp grammar project from here http://antlrcsharp.codeplex.com/releases/view/47523, and it runs fine.
But when I add 'output=AST' to the grammar, I get a TON of errors:
I am admittedly new to ANTLR, so I am not sure how to proceed at this point. I would have assumed this type would have existed in the antlr csharp runtime dll, but obviously not. Has anyone come across this problem before?
I ran into this migrating from a v3.2 script generating from the Java tool to using v3.4 with the dotNet build tools.
I was able to figure out (thx to the documentation that comes with the .net VS integration) that the problem with not getting the right return type was because a class is only generated if you have a return type on the rule. Adding a dummy integer return type to my rules that had no return value cleared that up.
There is a discussion of the rule returns in the C# generator and target in the documentation from the C# target page at antlr, follow the link at the top of the page and check out section 4.1.1 "Return values"
About a year ago I did a project with Antlr and ran into an issue where I got tons of errors. As odd as it sounds but by using an older runtime I got it to work. I think I used a dll that had been compiled for the 2.0 .Net Framework.
I do not remember exactly what the error was or what had actually caused it. All I remember is that it solved the issue. I have no idea if this will help in your situation but it's worth a shot if you are stuck.
You are not the first person to have this problem. The patch at https://github.com/antlr/antlr/pull/1 addresses it by providing the missing file. Include it in your source and recompile.

Are there any emacs or vim editors with code completion plugins for C#?

It would be nice if it did both a list of methods to choose from and the list of potential input parameters. This was done for powershell and I was curious if there was any similar functionality implemented for emacs or vim?
Clarification:
A fellow developer I work with wants to use either vim or emacs for the low overhead without running visual studio. In essence he would like to be able to write tests, edit code in emacs or vim then just run NANT scripts to compile the code and run the tests. The only feature from Visual Studio he wants is code completion. The rest he can live without for 98-99 percent of the time.
You can use a vim editor emulator for Visual Studio.
http://www.viemu.com/
I haven't come across an emacs mode that would offer code completion suggestions based on "knowledge" of the API(s) that the user's environment is offering. To a lot of people this is an issue which prevents them from attempting to use Emacs or VIM when working with rich/large/unwieldy (delete as applicable) APIs.
However I am wondering how much of a problem this would present during day-to-day work. I've been using Emacs with C#-mode to crank out quite a lot of C# code. I also tend to run dabbrev-mode or pabbrev-mode, which tends to take care of the more common function and variable names I tend to use. To my eternal shame I have to admit that I tend to have a browser open on the MSDN website to look up the rest - those APIs that I don't use often enough to remember. Another potential helper that your colleague might want to look into is icicles, which may also be a step in the right direction. Neither of these libraries however will offer the full breadth of completion support that something the like Visual Studio IDE will offer. I'd see this as part of the trade-off when using a more efficient editor.
As an aside, if your colleague is working in a team and other members working on the same project are using Visual Studio, MSBuild might offer a better solution for building outside of VS than Nant as MSBuild reads the same solution and project files that VS uses (in fact a lot of the build work in VS2008 is handled by MSBuild). The syntax isn't too far away from Nant and with the community tasks added (which gives you NUnit integration etc) and it'll ensure that everybody is using very similar mechanisms to build the executables.
The furthest along completion I've seen for C# is at this blog, specifically at this post. (Blog link included for context and other Emacs posts.)
If you can live with dumb completion, you might be able to roll your own with tags and tag completion.
A previous stack on the same issue.
Your source code should be processed through the CEDET framework: http://cedet.sourceforge.net/
Then either use the example UIs bundled with cedet or else try any of these two:
- company-mode: http://nschum.de/src/emacs/company-mode
- completion-ui: http://www.dr-qubit.org/emacs.php
both supporting CEDET as a completion search backend.
apa!
for emacs and C# you can look at this tool : http://code.google.com/p/idebridge/
OmniSharp provides contextual intellisense for C# in vim.
Some of the suggestions in Eclipse Style Function Completions in Emacs for C, C++ and JAVA? may be relevant for emacs.
Not c# specific, but still.
I have found the http://code.google.com/p/csense this is an emacs c# intellisense/code sense. I found it from this blog post http://osdir.com/ml/emacs.sources/2007-11/msg00018.html, this may be close to the answer I was looking for.
After looking further it has not been updated since November 2007, looks stale to me.
For Vim, you can install insenvim. It support for the C# code completion.
After download the plugin you could install the installation file or install manually by following steps:
Copy the file cs_vis.vim into your $VIM\vimfiles\ftplugin directory.
Copy the file csft.dll into your $VIM_INTELLISENSE directory.
Copy CSVimHelper.dll,reg.bat to your $VIM_INTELLISENSE directory.
Run reg.bat to register the dlls. You need to set the directory gacutil.exe
in the path. You need the latest version of .NET SDK.

Categories