forked from zippy/ceptr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceptr-eclipse-csharp-interface.txt
138 lines (96 loc) · 4.04 KB
/
ceptr-eclipse-csharp-interface.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
====================================
Cygwin vs. MinGW
====================================
Please note that at the present time, the Cygwin tool chain results in a non-descript make file error. Ceptr builds correctly with the MinGW toolchain, which can be downloaded here: http://sourceforge.net/projects/mingw/files/
I simply downloaded the latest version, and then selected the appropriate options from the package list (GCC, etc.)
====================================
Building ceptr as an executable in Eclipse
====================================
In Eclipse:
File -> New -> C Project
Enter the project name (ceptr)
Select Executable -> Empty Project
Select MinGW GCC as the toolchain
Right-click on the new project:
New -> Source Folder
Enter "src"
Right-click on the new project:
New -> Source Folder
Enter "spec"
Drag and drop the files in your ceptr folder (cloned from GitHub) into the Eclipse source folder
Select "Link to files" so that when you rebase, Eclipse gets the changes.
Do the same for the files in the "spec" folder, dropping them as links into the Eclipse "spec" folder.
Build and run.
Select the dropdown on the "run" icon (round green symbol with a white arrow)
Select C/C++ Application on the left
Click "New" (the first icon with a "+" symbol in the upper right corner)
Click "Run"
In ceptr.h, comment out:
#include <pthread.h>
as I haven't figured out how to include support for pthread in Windows. Some references:
http://stackoverflow.com/questions/2150938/can-i-get-cs-pthread-h-to-compile-in-windows
http://sourceware.org/pthreads-win32/
You can from then on run the program, if you have more than one project in your workspace, use the dropdown on the "run" icon to select the desired project.
====================================
Building ceptr as a shared library in Eclipse
====================================
In Eclipse:
File -> New -> C Project
Enter the project name (ceptrlib)
Select Shared Library -> Empty Project
Select MinGW GCC as the toolchain
Right-click on the new project:
New -> Source Folder
Enter "src"
Drag and drop the files in your ceptr folder (cloned from GitHub) into the Eclipse source folder
Select "Link to files" so that when you rebase, Eclipse gets the changes.
This create "libceptrlib.dll" (annoyingly, Eclipse added "lib" at the beginning of the project, but we can't name our project "ceptr" because it conflicts with the executable version.
The resulting dll is in c:\Users\[you]\workspace\ceptrlib\Debug as libceptrlib.dll
====================================
Calling C functions from C#
====================================
Create a simple "test.c" function in ceptrlib/src:
#include "stdio.h"
void Test()
{
printf("Hello World\r\n");
}
Create a C# console application. Copy the libceptrlib.dll into the bin\Debug folder of your new project.
Change Program.cs to read:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ceptrlibtest
{
class Program
{
[DllImport("libceptrlib.dll")]
extern static void Test();
static void Main(string[] args)
{
Test();
}
}
}
Run it. The output in the console window will be:
Hello World
Press any key to continue...
*** Further documentation on DllImport and working with the T structure will be forthcoming. ***
====================================
Building the csharp-ide for ceptr in Windows
====================================
Requirements:
Visual Studio 2012 (Express does not support sub-folders, to my knowledge)
.NET Framework 4.5
Open the solution in ceptr/csharp-ide and build the solution.
====================================
Building the csharp-ide for ceptr in Ubuntu
====================================
Install Mono and Wine
*** further details on how to do that will be forthcoming. ***
In the ceptr/csharp-ide directory:
xbuild
The resulting executable should be in ceptr/csharp-ide/bin/Debug