mystor / rust-cpp

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

Failed to compile #59

Closed Hirrolot closed 5 years ago

Hirrolot commented 5 years ago

I am trying to build my library which uses cpp.

src/build.rs:

fn main() {
    cpp_build::build("src/lib.rs");
}

src/lib.rs:

#[macro_use]
extern crate cpp;

cpp! {{
    #include <stdio.h>
}}

fn foo() {
    cpp!([] {
        printf("Hello, World!\n");
    });
}

After that I executed cargo build, and received the error:

error: proc-macro derive panicked
  --> src/lib.rs:9:2
   |
9  |       cpp!([] {
   |  _____^
10 | |         printf("Hello, World!\n");
11 | |     });
   | |_______^
   |
   = help: message: 
           -- rust-cpp fatal error --

           The OUT_DIR environment variable was not set.
           NOTE: rustc must be run by Cargo.: NotPresent
   = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

error: Could not compile `cpp`.

To learn more, run the command again with --verbose.

How to fix it? Also note that if I have a binary project, no errors are displayed.

Hirrolot commented 5 years ago

I'll close this issue, I just examined that I have specified the wrong source path for the build() function.