-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include! uses relative path, which breaks for dependencies #367
Comments
This is supposed to work, though admittedly not well tested on Windows. Take a look at https://docs.rs/cxx-build/0.5.2/cxx_build/static.CFG.html for some discussion of how the include paths are arranged. In particular, when using cxx-build, your include!("cxx-example/include/demo.h"); If it does not work that way, would it be possible for you to provide a minimal repro with the cxx-example and cxx-depend crates, as a small git repository or tarball? |
Separately, I notice the following output in your error message: |
True, forgot to mention I added the current crate's root directory in an attempt to fix this error.
Now I remove that extra include dir and change the
Translated, it means the type is re-defined, effectively the header file is compiled multiple times.
#pragma once
#include "rust/cxx.h"
#include <memory>
#include <string>
namespace org {
namespace example {
class ThingC {
public:
ThingC(std::string appname);
~ThingC();
std::string appname;
};
struct SharedThing;
std::unique_ptr<ThingC> make_demo(rust::Str appname);
const std::string &get_name(const ThingC &thing);
void do_thing(SharedThing state);
} // namespace example
} // namespace org To me, it looks a bit like the MSVC compiler cannot recognize To verify that, I set up a small test in a new empty directory. First, create a sub-directory
Then, add a .hpp and .cpp file: // include/simple.hpp
#pragma once
class MyClass {}; // simple.cpp
#include "include/simple.hpp"
#include "symlink/simple.hpp"
int main() {
MyClass m;
} Now compile:
Exactly the same problem. The obvious fix would be traditional header guards, but maybe it can be avoided to include the header through multiple paths in the first place? Because including through symlinks per se is not a problem on MSVC. |
Would you be able to provide a repro as a git repo or tarball that I can just run $ exa -T
.
├── include
│ └── simple.hpp
├── simple.cpp
└── symlink -> include
$ clang++ simple.cpp; echo $?
0
$ g++ simple.cpp; echo $?
0 |
I wrote an entire post explaining the errors, but eventually I could get it to work (working example in this repo). I had a lot of problems reproducing the errors. What surprised me is that incremental compilation was totally unreliable, several times a build failed or succeeded, only to do the opposite when deleting the This could be related to In case someone is interested in the (now solved) errors#pragma onceLooks like the #include "../include/demo.h" // instead of #include "cxx-example/include/demo.h"
#include "cxx-example/src/main.rs.h"
#include <iostream> Nevertheless good to know that symlinks and Anyway, the problem still persists, I created https://github.com/Bromeon/cxx-example to reproduce it. Using lib instead of binWhen changing src/demo.cc(2): fatal error C1083:
Datei (Include) kann nicht geöffnet werden: "cxx-example/src/main.rs.h": No such file or directory I adapted the references in Generally I'm struggling a bit with the many implicit things that are happening in cxx, such as:
There's probably a good reason for all those points, but it's quite involved to wire all the things together correctly 🙂 By the way, is there an easy way to show |
I'll go ahead and close this since everything you described appears working as designed. In the future please consider providing a simple repro up front when opening an issue. You changed the include to "../include/demo.h" or you renamed a file without fixing the places importing the file are probably not things that someone could have identified as the problem based on your comments. We'll have detailed documentation of how things are wired together on https://cxx.rs just as soon as I get a chance to write the content; tracked in #179. |
You're totally right, sorry for that and I'll keep it in mind. The changes you mentioned were early attempts to get it working, after your explanation of Nevertheless, thanks a lot for this, I learned a lot during this issue. Also glad to hear you're planning to write extended docs. In order to prevent others from doing the same mistakes, would it make sense if |
Sure thing -- that would be terrific. |
Let's assume project
cxx-example
has a bridge module, which sets up the C++ bindings. I took it mostly from thecxx-demo
crate inside the main repo.The
include!
is translated to verbatim#include "include/demo.h
in C++. Which file this refers to, depends on the include paths on thecc::Build
configuration inbuild.rs
.If I make another project
cxx-depend
which usescxx-example
as a dependency, then it fails with:Note that it fails at
cxx-example
(not the current cratecxx-depend
), which I just successfully compiled.In the error output, you see that the include paths refer to the current crate, although some included files (e.g.
cxx-example/include/demo.h
) are in the source tree ofcxx-example
. It seems likeinclude!(...)
does not take that into account.The include directory is specified at
cxx/gen/build/src/lib.rs
Line 190 in e37ce2f
<absolutePath>/cxx/target/debug/buildcxx-test-suite-6970f6e2077e6b4d/out/cxxbridge/include
, i.e. pointing to the files in thetarget
directory.Maybe a general question: is
include!
really the best name for this macro? It took me quite a while that this is not Rust'sinclude!
, but effectively equivalent to a C++#include
. Wouldn't something likecxx_include!
be clearer?The text was updated successfully, but these errors were encountered: