<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.haidhi.my.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Cara_binding_C%2B%2B_dan_Rust</id>
	<title>Cara binding C++ dan Rust - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.haidhi.my.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Cara_binding_C%2B%2B_dan_Rust"/>
	<link rel="alternate" type="text/html" href="https://wiki.haidhi.my.id/wiki/index.php?title=Cara_binding_C%2B%2B_dan_Rust&amp;action=history"/>
	<updated>2026-11-01T21:44:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.haidhi.my.id/wiki/index.php?title=Cara_binding_C%2B%2B_dan_Rust&amp;diff=608&amp;oldid=prev</id>
		<title>SanzSkuy: Created page with &quot;Buat project rust &lt;syntaxhighlight lang=bash&gt; cargo new --lib rust_code &lt;/syntaxhighlight&gt;  Cargo.toml &lt;syntaxhighlight lang=toml&gt; [package] name = &quot;rust_code&quot; version = &quot;0.1.0&quot; edition = &quot;2024&quot;  [dependencies]  [lib] crate-type = [&quot;staticlib&quot;] &lt;/syntaxhighlight&gt;  lalu contoh &lt;code&gt;src/lib.rs&lt;/code&gt; &lt;syntaxhighlight lang=rust&gt; #[unsafe(no_mangle)] pub extern &quot;C&quot; fn hello_from_rust() {     println!(&quot;Hello from Rust&quot;); }  #[unsafe(no_mangle)] pub extern &quot;C&quot; fn add_number(a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.haidhi.my.id/wiki/index.php?title=Cara_binding_C%2B%2B_dan_Rust&amp;diff=608&amp;oldid=prev"/>
		<updated>2026-03-12T07:16:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Buat project rust &amp;lt;syntaxhighlight lang=bash&amp;gt; cargo new --lib rust_code &amp;lt;/syntaxhighlight&amp;gt;  Cargo.toml &amp;lt;syntaxhighlight lang=toml&amp;gt; [package] name = &amp;quot;rust_code&amp;quot; version = &amp;quot;0.1.0&amp;quot; edition = &amp;quot;2024&amp;quot;  [dependencies]  [lib] crate-type = [&amp;quot;staticlib&amp;quot;] &amp;lt;/syntaxhighlight&amp;gt;  lalu contoh &amp;lt;code&amp;gt;src/lib.rs&amp;lt;/code&amp;gt; &amp;lt;syntaxhighlight lang=rust&amp;gt; #[unsafe(no_mangle)] pub extern &amp;quot;C&amp;quot; fn hello_from_rust() {     println!(&amp;quot;Hello from Rust&amp;quot;); }  #[unsafe(no_mangle)] pub extern &amp;quot;C&amp;quot; fn add_number(a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Buat project rust&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
cargo new --lib rust_code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo.toml&lt;br /&gt;
&amp;lt;syntaxhighlight lang=toml&amp;gt;&lt;br /&gt;
[package]&lt;br /&gt;
name = &amp;quot;rust_code&amp;quot;&lt;br /&gt;
version = &amp;quot;0.1.0&amp;quot;&lt;br /&gt;
edition = &amp;quot;2024&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[dependencies]&lt;br /&gt;
&lt;br /&gt;
[lib]&lt;br /&gt;
crate-type = [&amp;quot;staticlib&amp;quot;]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lalu contoh &amp;lt;code&amp;gt;src/lib.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=rust&amp;gt;&lt;br /&gt;
#[unsafe(no_mangle)]&lt;br /&gt;
pub extern &amp;quot;C&amp;quot; fn hello_from_rust() {&lt;br /&gt;
    println!(&amp;quot;Hello from Rust&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#[unsafe(no_mangle)]&lt;br /&gt;
pub extern &amp;quot;C&amp;quot; fn add_number(a: i32, b: i32) -&amp;gt; i32 {&lt;br /&gt;
    a + b&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lalu di luar project Rust, code C++&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
    void hello_from_rust();&lt;br /&gt;
    int add_number(int a, int b);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;C++ code is running&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    &lt;br /&gt;
    hello_from_rust();&lt;br /&gt;
    &lt;br /&gt;
    int result = add_number(10, 5);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Rust add_number result &amp;quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    &lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Cara compile dan run =&lt;br /&gt;
Buat &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt;, isinya kayak gini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=makefile&amp;gt;&lt;br /&gt;
.PHONY: compile_rust compile run&lt;br /&gt;
&lt;br /&gt;
compile_rust:&lt;br /&gt;
	cd rust_code &amp;amp;&amp;amp; cargo build --release&lt;br /&gt;
&lt;br /&gt;
compile: compile_rust&lt;br /&gt;
	g++ main.cpp -o app -L./rust_code/target/release -lrust_code -lpthread -ldl -lrt&lt;br /&gt;
&lt;br /&gt;
run: compile&lt;br /&gt;
	./app&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lalu run dengan ketik &amp;lt;code&amp;gt;make run&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>SanzSkuy</name></author>
	</entry>
</feed>