Cxx.jl, nested includes, error: unknown type name and ERROR: Could not find $class in translation unit

cxx

#1

I am trying to use the C++ library Box2D (forked here simply to have a shared library build): https://github.com/goretkin/Box2D/tree/master/Box2D

My issue might just be that I do not know how to include a header which includes headers from an include directory.

This is what I tried:

using Cxx

const path_to_lib = "/Users/goretkin/repos/Box2D/Box2D/Build/gmake/bin/Debug"

addHeaderDir(path_to_lib, kind=C_System)
Libdl.dlopen(path_to_lib * "/libBox2Ddyn.dylib", Libdl.RTLD_GLOBAL)

And then run

julia> cxx"#include \"/Users/goretkin/repos/Box2D/Box2D/Box2D/Box2D.h\""
In file included from :1:
In file included from __cxxjl_12.cpp:1:
/Users/goretkin/repos/Box2D/Box2D/Box2D/Box2D.h:34:10: fatal error: 'Box2D/Common/b2Settings.h' file not found
#include "Box2D/Common/b2Settings.h"
         ^
true

julia> cxx"#include \"/Users/goretkin/repos/Box2D/Box2D/Box2D/Box2D.h\""
true

I can’t tell whether it succeeded the second time, or it was quiet about failing. My guess is that it’s quiet about failing. The same behavior is true with cxxinclude("/Users/goretkin/repos/Box2D/Box2D/Box2D/Box2D.h"). It seems it doesn’t matter if I try to addHeaderDir the directory which contains Box2D/Common/b2Settings.h.

I remained hopeful and tried

julia> @cxxnew b2Vec2()
ERROR: Could not find `b2Vec2` in translation unit

julia> cxx"
              #include \"/Users/goretkin/repos/Box2D/Box2D/Box2D/Box2D.h\"
              b2Vec2 gravity(0.0f, -10.0f); "
__cxxjl_11.cpp:3:8: error: unknown type name 'b2Vec2'
       b2Vec2 gravity(0.0f, -10.0f); 
       ^
true

I’m on

julia> VERSION
v"0.5.2"

julia> Pkg.installed("Cxx")
v"0.1.1"

And I think this is not relevant yet, but

$ nm libBox2Ddyn.dylib  | c++filt | grep "b2Vec2("
0000000000001df0 unsigned short b2Vec2::b2Vec2(float, float)
0000000000001fc0 unsigned short b2Vec2::b2Vec2()
0000000000001e20 unsigned short b2Vec2::b2Vec2(float, float)
0000000000001fe0 unsigned short b2Vec2::b2Vec2()

Thanks!


#2

This doesn’t look right – that’s a build path. You probably need something like /Users/goretkin/repos/Box2D/Box2D/ (whatever is the parent directory of the Box2D directory).

edit: to clarify, addHeaderDir does the same thing as -I on the command line; the compiler then looks in that path for a sub-path of Box2D/Common/b2Settings.h when processing #include "Box2D/Common/b2Settings.h".


#3

Thanks for confirming that. I thought it was a little fishy and now I realized I generalized incorrectly from the example in the Cxx.jl README.

According to my first post I did try to add the correct header dir

but actually I had made a mistake (one too many Box2Ds), so thank you!