mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
802 stars 44 forks source link

Using elements defined in `cpp!` macro in other cpp files #113

Open ttzytt opened 3 months ago

ttzytt commented 3 months ago

From the example provided, I know that you can include other libraries in the C++ blocks:

cpp!{{
    #include <iostream>
}}

I'm wondering if it is possible to use things defined in cpp! macros in other C++ files. For example, one can define a function in the block like this:

cpp!{{
    #include <iostream>
    int cpp_func(){
        return 42;
    }
}}

Are there any ways for other cpp files to use the function cpp_func?

If this is possible, then I believe this project can also be used to embed Rust code in C++, as one can wrap all the C++ code by cpp! and insert Rust by rust!.

Also, is it possible to open a discussion page for this project? I believe it is more suitable to place questions like this on the discussion page.