-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
SET PATH=c:\Program Files\Java\jdk-panama-nightly\bin\;%PATH% | ||
SET JAVA_HOME=c:\Program Files\Java\jdk-panama-nightly\ | ||
|
||
rd /s /q target | ||
|
||
mkdir target\g++ | ||
g++ -shared -static -o target\g++\helloworldcpp.dll -Wall helloworldcpp.cpp | ||
|
||
jextract --source -d target\jextract\classes --target-package com.github.tornaia.panama.tutorial004.cpp -I target\g++ -l helloworldcpp helloworldcpp.h | ||
jextract -d target\jextract\classes --target-package com.github.tornaia.panama.tutorial004.cpp -I target\g++ -l helloworldcpp helloworldcpp.h | ||
|
||
mkdir target\jar | ||
jar -cvf target\jar\helloworldcpp.h.jar -C target\jextract\classes . | ||
|
||
jdeps --generate-module-info target/jdeps --module-path panama.tutorial004c --add-modules jdk.incubator.foreign target\jar\helloworldcpp.h.jar | ||
del target\jar\helloworldcpp.h.jar | ||
|
||
copy target\jdeps\helloworldcpp.h\module-info.java target\jextract\classes\module-info.java | ||
javac -d target\jextract\classes target\jextract\classes\module-info.java | ||
|
||
jar -cvf target\jar\helloworldcpp.h.jar -C target\jextract\classes . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "helloworldcpp.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <stdio.h> | ||
|
||
extern int main() { | ||
std::cout << "Hello World from c++/main!" << std::endl; | ||
return 0; | ||
} | ||
|
||
extern int main2() { | ||
std::cout << "Hello World from c++/main2!" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef helloworldcpp_h | ||
#define helloworldcpp_h | ||
|
||
// https://stackoverflow.com/questions/53393585/why-name-mangling-has-no-effect-on-main-function-in-c | ||
extern int main(); | ||
|
||
// https://en.wikipedia.org/wiki/Name_mangling#Real-world_effects_of_C++_name_mangling | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern int main2(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* helloworldcpp_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>panama-tutorial-004</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<name>Panama Tutorial 004</name> | ||
|
||
<parent> | ||
<groupId>com.github.tornaia</groupId> | ||
<artifactId>panama-tutorial-parent</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.tornaia</groupId> | ||
<artifactId>panama-tutorial-004-cpp</artifactId> | ||
<version>${project.version}</version> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/lib/target/jar/helloworldcpp.h.jar</systemPath> | ||
</dependency> | ||
</dependencies> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
panama-tutorial-004/src/main/java/com/github/tornaia/panama/tutorial004/Tutorial004.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.tornaia.panama.tutorial004; | ||
|
||
import com.github.tornaia.panama.tutorial004.cpp.helloworldcpp_h; | ||
|
||
public class Tutorial004 { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Start"); | ||
helloworldcpp_h.main(); | ||
helloworldcpp_h.main2(); | ||
System.out.println("End"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module panama.tutorial004j { | ||
requires jdk.incubator.foreign; | ||
requires helloworldcpp.h; | ||
} |
11 changes: 11 additions & 0 deletions
11
panama-tutorial-004/src/test/java/com/github/tornaia/panama/tutorial004/Tutorial004Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.tornaia.panama.tutorial004; | ||
|
||
import org.junit.Test; | ||
|
||
public class Tutorial004Test { | ||
|
||
@Test | ||
public void test() { | ||
Tutorial004.main(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters