Skip to content

Commit efe6a8b

Browse files
committed
switched to latest .net core 2.2.1. added CMake. minor fixes
1 parent 6695be7 commit efe6a8b

9 files changed

Lines changed: 58 additions & 55 deletions

File tree

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dynamicLinker"]
2+
path = dynamicLinker
3+
url = https://github.com/Marqin/dynamicLinker

‎CMakeLists.txt‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required (VERSION 3.8)
2+
project (ASA4J)
3+
4+
# TODO wall
5+
set(CMAKE_CXX_STANDARD 14)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# 64bit compile
9+
SET(CMAKE_CXX_FLAGS "-m64")
10+
SET(CMAKE_C_FLAGS "-m64")
11+
SET(CMAKE_EXE_LINKER_FLAGS "-m64")
12+
SET(CMAKE_MODULE_LINKER_FLAGS "-m64")
13+
SET(CMAKE_SHARED_LINKER_FLAGS "-m64")
14+
15+
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # fPIC
16+
17+
find_package(JNI REQUIRED)
18+
find_package(Java REQUIRED)
19+
include(UseJava)
20+
21+
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
22+
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
23+
24+
add_library(tar SHARED CoreCLRHost.cpp CoreCLRHost.hpp utils.hpp Sample1.h
25+
dynamicLinker/dynamicLinker.cpp)
26+
target_link_libraries(tar dl stdc++fs)
27+
target_include_directories(tar PUBLIC ${JNI_INCLUDE_DIRS} dynamicLinker)
28+
29+
add_jar(sample1 Sample1.java GENERATE_NATIVE_HEADERS sample-native)
30+
31+
execute_process(COMMAND dotnet build)

‎CoreCLRHost.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int runFromEntryPoint(
5151
std::cerr << e.what() << std::endl;
5252
return -1;
5353
} catch ( dynamicLinker::dynamicLinkerException e ) {
54-
std::cerr << e.what() << std::endl;
54+
std::cerr << "dynamicLinkerEx: " << e.what() << std::endl;
5555
return -1;
5656
}
5757

@@ -215,8 +215,8 @@ JNIEXPORT jint JNICALL Java_Sample1_coreClrHost(JNIEnv *env, jobject obj, jstrin
215215
assemblyDir = cwd + assemblyDir;
216216

217217
int exitCode = runFromEntryPoint(
218-
cwd+std::string("./tar.so"), // absolute path to this exe
219-
std::string("/usr/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview1-002111-00/"), // absolute path to coreCLR DLLs
218+
cwd, //+std::string("./tar.so"), // absolute path to this exe
219+
std::string("/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.1/"), // absolute path to coreCLR DLLs
220220
assemblyDir, // absolute path to DLL to run
221221
assemblyName,
222222
std::string("Managed"),

‎CoreCLRHost.hpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
*/
55

6-
//#pragma once
6+
#pragma once
77

8-
//#if not defined (__unix__) && not defined(__unix) && not defined (unix) && ( (not defined (__APPLE__) || not defined (__MACH__)) )
9-
// #error THIS SOFTWARE IS ONLY FOR UNIX-LIKE SYSTEMS!
10-
//#endif
8+
#if not defined (__unix__) && not defined(__unix) && not defined (unix) && ( (not defined (__APPLE__) || not defined (__MACH__)) )
9+
#error THIS SOFTWARE IS ONLY FOR UNIX-LIKE SYSTEMS!
10+
#endif
1111

1212
#include <functional>
1313
#include <iostream>
@@ -25,11 +25,11 @@
2525
#define PATH_MAX FILENAME_MAX
2626
#endif
2727

28-
//#if defined(__APPLE__)
29-
// std::string coreClrDll = "libcoreclr.dylib";
30-
//#else
28+
#if defined(__APPLE__)
29+
std::string coreClrDll = "libcoreclr.dylib";
30+
#else
3131
std::string coreClrDll = "libcoreclr.so";
32-
//#endif
32+
#endif
3333

3434
class myClass {
3535
private:

‎Makefile‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎Managed.csproj‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>library</OutputType>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
</PropertyGroup>
7+
</Project>

‎README.md‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ JDK: You should edit the Makefile and set the JAVALIB PATH
1111
gcc 6: std C++ 14 for the filesystem
1212

1313
# usage:
14-
javac Sample1.java
14+
cmake .
15+
cmake --build .
1516

16-
javah Sample1
17-
18-
make
19-
20-
cd cs
21-
22-
dotnet restore
23-
24-
dotnet build
25-
26-
java Sample1
17+
java -cp sample1.jar Sample1
2718

2819

2920
`You should keep the compiled file in the same fold.`

‎Sample1.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Sample1
88
public static void main(String[] args)
99
{
1010
//System.loadLibrary("Sample1");
11-
System.load("./tar.so");
11+
System.load(System.getProperty("user.dir") + java.io.File.separator + "libtar.so");
1212

1313
Sample1 sample = new Sample1();
1414
int square = sample.intMethod(5);
@@ -17,7 +17,7 @@ public static void main(String[] args)
1717
int sum = sample.intArrayMethod(new int[]{1,1,2,3,5,8,13});
1818

1919
int success=0;
20-
success= sample.coreClrHost("./Managed.dll");
20+
success= sample.coreClrHost("./bin/Debug/netcoreapp2.2/Managed.dll");
2121
System.out.println("intMethod: "+ square);
2222
System.out.println("boolMethod: "+ bool);
2323
System.out.println("stringMethod: "+ text);

‎dynamicLinker‎

Submodule dynamicLinker added at ba66435

0 commit comments

Comments
 (0)