Some basic questions

325 views
Skip to first unread message

Voidpointer Linden

unread,
Apr 30, 2014, 3:21:50 PM4/30/14
to cppsha...@googlegroups.com
1)
What reader is used for .md files?   Windows doesn't seem to know what it is and thus the only way to read them is to look at them on the repo website.

2)
The GettingStarted file talks about creating a class to generate bindings.   Looks like that class is in C# and judging by the code in the "Examples/SDL" directory, that looks to be the case.   So I tried the example by basically running it, but nothing gets created.   I even set the output dir to some absolute dir and all it did was create an empty directory.   I'm assuming the binding code should be getting generated, but there's no error output or anything to tell me what's going wrong.

3)
Am I even going down the right path by trying to generate the bindings by running the examples/SDL project?   Or is there some other thing I need to do?

4)
Is there a way to find out why it's not generating anything?


To pre-answer some questions:
* I'm on a Windows machine (Win7-64) using Visual Studio 2013.   
* I followed the instructions to build LLVM and Clang using cmake (and I even made sure I was only getting the code up to the revisions noted in the getting started page) and they seemed to build fine
* I ran GenerateProjects.bat - wasn't really sure whether to choose "Visual Studio 12" or the "Visual Studio 12 (C++ parser)" option.   The generated sln without the (C++ parser) didn't quite compile (complained about not being able to find DataTypes.h), but the option with (C++ parser) seemed to compile fine, so I ended up using that.
* I then set the examples/SDL project to the startup project and ran it (with the above "no output" result)


João Matos

unread,
Apr 30, 2014, 3:36:18 PM4/30/14
to Voidpointer Linden, cppsha...@googlegroups.com
1) It's the standard Markdown format. You can use any text editor, Markdown Pad if you want some nicer formatting.

2) Yes, as opposed to some other tools where you invoke an executable, CppSharp is a library so you need to create an executable project where you link the library. This is desirable because then you can easily add some custom logic to your bindings with the full power of a programming language.

3) To be honest, I would not use the SDL example, but if you want to do this, you'll need to run download and extract the SDL header files from an SDL release. Run with Ctrl-F5 or from the console to be able to read the output of the tool. It will probably complain about not being able to find SDL.h.

4) Yes, read the output generated by the tool. You can also set `options.Verbose = true` to get some more detailed information.

 "Visual Studio 12 (C++ parser)" uses our new upcoming parser that does not use C++/CLI. If you get errors compiling the regular "Visual Studio 12" this probably means you didn't get the specified revisions correctly.

Let me know if you need further help.


--
You received this message because you are subscribed to the Google Groups "CppSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cppsharp-lis...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
João Matos

Voidpointer Linden

unread,
Apr 30, 2014, 3:55:15 PM4/30/14
to João Matos, cppsha...@googlegroups.com
2) I agree this is desirable.   I've used SWIG for a long time and I actually appreciate the simplicity of the way you've done it!

3) Is there a better example to use?


The revisions I used are:
LLVM:  r202563 "[Sparc] Emit 'restore' instead of 'restore %g0, %g0, %g0'. This improves the readability of the generated code."
Clang:  r202562 "Fixed an assertion failure related to bitfield lowering. …"
CppSharp:  Changeset 2082 (5ae3dffed8db) "Update GettingStarted.md …"

* I created <CppSharp>/deps/llvm/build and cd'd into that dir
* I then ran the cmake gui
** Source Code dir was <CppSharp>/deps/llvm
** Output Dir was <CppSharp>/deps/llvm/build
** I chose Visual Studio 12 for the output type
** I hit the "Configure" button, but did not touch any configuration options that showed up (i.e. I left the default settings)
** I then his "generate" which created the llvm.sln file
* I then loaded llvm.sln into VS2013, set to "RelWithDbgInfo" config and compiled.   This seemed to compile (though there were warnings)
* I then went into <CppSharp>/build and ran GenerateProjects.bat, choosing the "Visual Studio 12 (C++ Parser)" option (since the normal option didn't seem to compile)
** This generated a <CppSharp>/vs2013/CppCharp.sln file as well as some subdirs (lib, etc)
* I compiled cppsharp.sln and tried running the example

Where in that process do you suspect I went wrong?





--

Lee Wilson | Senior Engineer

O None | C 425.890.5463 | Skype devnullicus | Second Life Voidpointer Linden


Linden Lab | Makers of Shared Creative Spaces

Check out what we're working on!

João Matos

unread,
Apr 30, 2014, 4:07:22 PM4/30/14
to Voidpointer Linden, cppsha...@googlegroups.com

On Wed, Apr 30, 2014 at 8:55 PM, Voidpointer Linden <voidp...@lindenlab.com> wrote:
* I then went into <CppSharp>/build and ran GenerateProjects.bat, choosing the "Visual Studio 12 (C++ Parser)" option (since the normal option didn't seem to compile)

You can use the new parser, but the old one is still more stable. I only recommend using the new parser for OSX and Linux where it is the only available option.

What compile problem did you get with the regular option for VS2012 (that is, non C++ Parser option)? As long as you use the specified versions of LLVM and Clang they should compile fine.

As for examples, I will link you to a couple of real-world usages of the tool.

The first is the parser generator that CppSharp itself uses to bootstrap itself:


Then for more complex usage, you can look through these real-world uses:



The passes you need depend a lot on your source inputs so ask if you don't know how to best achieve something with the tool.

--
João Matos

Voidpointer Linden

unread,
Apr 30, 2014, 5:46:15 PM4/30/14
to João Matos, cppsha...@googlegroups.com
I decided to delete the built stuff and try again from scratch.   The steps are the same as described above (using ReleaseWithDebInfo/win32 config for LLVM and release/x86 config for CppSharp).   One thing that I did notice is when I loaded the generated CppSharp.sln for the first time, VS2013 wanted to upgrade a bunch of the projects:

Upgrading project 'Basic.CLI'...
Configuration 'Debug|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Debug|x64': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|x64': no upgrade required. Platform Toolset is 'v120'.
TargetFrameworkVersion = v4.5 (was v4.0)
Upgrading project 'CLITemp.CLI'...
Configuration 'Debug|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Debug|x64': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|x64': no upgrade required. Platform Toolset is 'v120'.
TargetFrameworkVersion = v4.5 (was v4.0)
Upgrading project 'STL.CLI'...
Configuration 'Debug|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Debug|x64': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|x64': no upgrade required. Platform Toolset is 'v120'.
TargetFrameworkVersion = v4.5 (was v4.0)
Upgrading project 'CppSharp.Parser.CLI'...
Configuration 'Debug|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Debug|x64': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|x64': no upgrade required. Platform Toolset is 'v120'.
TargetFrameworkVersion = v4.5 (was v4.0)
Upgrading project 'CppSharp.Parser'...
Configuration 'Debug|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Debug|x64': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|Win32': no upgrade required. Platform Toolset is 'v120'.
Configuration 'Release|x64': no upgrade required. Platform Toolset is 'v120'.
TargetFrameworkVersion = v4.5 (was v4.0)
Retargeting End: 5 completed, 0 failed, 0 skipped

 I tried option 4 again as per your suggestion (i.e. Visual Studio 2013 - without the C++ Parser) and when I compile, I get the following output:
(Trimmed for readability)

4><CppSharp>\tests\stl\STL.h(9): warning C4251: 'TestVectors::IntVector' : class 'std::vector<int,std::allocator<_Ty>>' needs to have dll-interface to be used by clients of struct 'TestVectors'
6>     Creating library ..\lib\Release_x32\CLITemp.Native.lib and object ..\lib\Release_x32\CLITemp.Native.exp
4>          with
8>     Creating library ..\lib\Release_x32\CSharpTemp.Native.lib and object ..\lib\Release_x32\CSharpTemp.Native.exp
4>          [
4>              _Ty=int
4>          ]
1><CppSharp>\src\AST\Type.cs(230,25,230,36): warning CS0109: The member 'CppSharp.AST.PointerType.IsReference' does not hide an inherited member. The new keyword is not required.
3><CppSharp>\tests\basic\basic.cpp(233): warning C4717: 'operator|' : recursive on all control paths, function will cause runtime stack overflow
10><CppSharp>\src\Parser\Parser.cpp : warning C4793: 'clang::ExternalASTSource::`vcall'{20}'' : function compiled as native :
11><CppSharp>\src\CppParser\Bindings\CSharp\AST.cs(1505,41,1505,58): warning CS0660: 'CppSharp.Parser.AST.TemplateParameter' defines operator == or operator != but does not override Object.Equals(object o)
11><CppSharp>\src\CppParser\Bindings\CSharp\AST.cs(1505,41,1505,58): warning CS0661: 'CppSharp.Parser.AST.TemplateParameter' defines operator == or operator != but does not override Object.GetHashCode()
10>Parser.obj : warning LNK4248: unresolved typeref token (01000028) for 'clang.ASTMutationListener'; image may not run
10>Parser.obj : warning LNK4248: unresolved typeref token (01000029) for 'clang.ASTDeserializationListener'; image may not run
10>Parser.obj : warning LNK4248: unresolved typeref token (01000052) for 'clang.CodeCompleteConsumer'; image may not run
13>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3274: The primary reference "<CppSharp>\build\vs2013\projects\..\lib\Release_x32\CppSharp.Parser.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
13><CppSharp>\src\Core\Parser\Parser.cs(24,35,24,47): error CS0246: The type or namespace name 'ParserResult' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(29,31,29,43): error CS0246: The type or namespace name 'ParserResult' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(46,47,46,60): error CS0246: The type or namespace name 'ParserOptions' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(46,16,46,32): error CS0246: The type or namespace name 'ParserTargetInfo' could not be found (are you missing a using directive or an assembly reference?)
14>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3274: The primary reference "<CppSharp>\build\vs2013\projects\..\lib\Release_x32\CppSharp.Parser.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
14>CSC : error CS0006: Metadata file '<CppSharp>\build\vs2013\lib\Release_x32\CppSharp.dll' could not be found

The actual errors seem to be these:
13><CppSharp>\src\Core\Parser\Parser.cs(24,35,24,47): error CS0246: The type or namespace name 'ParserResult' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(29,31,29,43): error CS0246: The type or namespace name 'ParserResult' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(46,47,46,60): error CS0246: The type or namespace name 'ParserOptions' could not be found (are you missing a using directive or an assembly reference?)
13><CppSharp>\src\Core\Parser\Parser.cs(46,16,46,32): error CS0246: The type or namespace name 'ParserTargetInfo' could not be found (are you missing a using directive or an assembly reference?)

However, it turns out that the conversion process of Visual Studio is the real issue.   When it updated the project files, it seems to have set the target framework to 4.5.  Having read in the gettingstarted that you require 4.5 Mono, I assumed that meant 4.5 .NET also.  It appears that was a mistake.   The fix in my case was to go through and modify the project properties for all the C# projects in CppSharp.sln to use a target framework of 4.5 instead of 4.0.   This made things compile.

When I then run the SDL example again with the verbose option on, I get the following output (which does explain why it's not working since it's expecting to find SDL installed at the specified location and I don't have SDL on this machine):

Parsing libraries...
Indexing library symbols...
Parsing code...
ignoring nonexistent directory "<CppSharp>\build\examples\SDL\SDL-2.0\include"
ignoring nonexistent directory ".\lib\clang\3.5\include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include
 C:\Program Files (x86)\Windows Kits\8.1\\include
End of search list.
File 'SDL.h' was not found
ignoring nonexistent directory "<CppSharp>\build\examples\SDL\SDL-2.0\include"
ignoring nonexistent directory ".\lib\clang\3.5\include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include
 C:\Program Files (x86)\Windows Kits\8.1\\include
End of search list.

One thing I am curious about though is why it's looking for the dir "<CppSharp>\build\examples\SDL\lib\clang\3.5\include" ?  Is that part of SDL normally?

Finally, I notice that in the C++ projects, it has these for additional include dirs:
..\..\..\deps\llvm\include
..\..\..\deps\llvm\tools\clang\include
..\..\..\deps\llvm\tools\clang\lib
..\..\..\deps\llvm\build\include
..\..\..\deps\llvm\build\tools\clang\include

All of those are fine and do exist except for the last one.  There is no llvm\build\tools directory.   Is there supposed to be?



João Matos

unread,
Apr 30, 2014, 6:05:22 PM4/30/14
to Voidpointer Linden, cppsha...@googlegroups.com

On Wed, Apr 30, 2014 at 10:46 PM, Voidpointer Linden <voidp...@lindenlab.com> wrote:
13>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3274: The primary reference "<CppSharp>\build\vs2013\projects\..\lib\Release_x32\CppSharp.Parser.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

From this error, it seems when you upgrade to 4.5, the C++/CLI compiled parser cannot use the C# assemblies (or vice-versa, can't easily tell from the errors). I think you'll be able to use 4.5 as long as you also change the version of all projects to be the same.

I pushed an update to the docs to warn about this.

One thing I am curious about though is why it's looking for the dir "<CppSharp>\build\examples\SDL\lib\clang\3.5\include" ?  Is that part of SDL normally?

This is being added by Clang itself, it provides some headers like `stdarg.h` and intrinsincs. It's generated by Clang as part of the build process, if you need those headers you'll need to copy them from the build output (for Debug here they're in `llvm\build\Debug\lib`) to your working directory.

All of those are fine and do exist except for the last one.  There is no llvm\build\tools directory.   Is there supposed to be?

I do have it on my machine, but if everything compiled fine then it's not a problem.

--
João Matos

Voidpointer Linden

unread,
Apr 30, 2014, 6:56:32 PM4/30/14
to João Matos, cppsha...@googlegroups.com
Alright, made a simple example following the code in GettingStarted.   Up until the section "Cleaning Up After You", things seem to work as they should.  I was able to output a binding class exactly as the doc said.

However, when I try to use this code from the next section:
void SetupPasses(Driver driver, PassBuilder passes)
{
    passes.RenameDeclsUpperCase(RenameTargets.Any);
    passes.FunctionToInstanceMethod();
}
it does not work because the ILibrary interface has a different definition for SetupPasses (that only includes the Driver param).
Is the code in the doc for the "new" C++ Parser code?   I'm fine with switching, but if you still recommend using the "old" version still for Windows, then is there any way to get an updated GettingStarted with code that works for the old ILibrary?

João Matos

unread,
Apr 30, 2014, 6:59:02 PM4/30/14
to Voidpointer Linden, cppsha...@googlegroups.com

On Wed, Apr 30, 2014 at 11:56 PM, Voidpointer Linden <voidp...@lindenlab.com> wrote:
Is the code in the doc for the "new" C++ Parser code?   I'm fine with switching, but if you still recommend using the "old" version still for Windows, then is there any way to get an updated GettingStarted with code that works for the old ILibrary?

The doc is just outdated.

IIRC you can use `driver.TranslationUnitPasses` instead of `passes`.




--
João Matos

Voidpointer Linden

unread,
Apr 30, 2014, 7:02:27 PM4/30/14
to João Matos, cppsha...@googlegroups.com
That works fine for the first option, but there doesn't seem to be an equivalent for the second line.   *shrug*  At this point, I have enough to get started on more than a toy example, so I'll do that and let you know if there are any other issues.

Thanks for all the help!

João Matos

unread,
Apr 30, 2014, 7:07:22 PM4/30/14
to Voidpointer Linden, cppsha...@googlegroups.com
We removed some of the helper extension methods some time ago.

You can do `driver.TranslationUnitPasses.Add(new FunctionToInstanceMethod())` instead.
--
João Matos

Voidpointer Linden

unread,
Apr 30, 2014, 7:33:38 PM4/30/14
to João Matos, cppsha...@googlegroups.com
        public void SetupPasses(Driver driver)
        {
            driver.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any);
            driver.TranslationUnitPasses.Add(new MethodConversionKind.FunctionToInstanceMethod());
        }

results in the errors:

1>SimpleExample1\SimpleExample1Gen1.cs(37,42,37,45): error CS1061: 'CppSharp.PassBuilder<CppSharp.Passes.TranslationUnitPass>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'CppSharp.PassBuilder<CppSharp.Passes.TranslationUnitPass>' could be found (are you missing a using directive or an assembly reference?)
1>SimpleExample1\SimpleExample1Gen1.cs(37,71,37,95): error CS0246: The type or namespace name 'FunctionToInstanceMethod' could not be found (are you missing a using directive or an assembly reference?)


Voidpointer Linden

unread,
Apr 30, 2014, 7:49:18 PM4/30/14
to João Matos, cppsha...@googlegroups.com
however,

public void SetupPasses(Driver driver) { driver.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any); driver.AddTranslationUnitPass(new FunctionToInstanceMethodPass()); }

works fine :)

Reply all
Reply to author
Forward
0 new messages