rust-qt / ritual

Use C++ libraries from Rust
Apache License 2.0
1.24k stars 49 forks source link

Problems generating code with pure virtual methods #1

Closed emoon closed 8 years ago

emoon commented 8 years ago

When generating code for qt_gui

qt/cpp_to_rust/gui/c_lib/source/src/qt_gui_c_QSyntaxHighlighter.cpp:4:15: error: allocating an object of abstract class type 'QSyntaxHighlighter'
  new(output) QSyntaxHighlighter(parent);

This is when generating code for Qt 5.7 on Mac (using the travis branch)

Riateche commented 8 years ago

Did you use -d flag to specify QtCore dependency? It will not work without -d because QSyntaxHighlighter's pure virtual function uses QString and QString is declared in QtCore, so the function will be skipped and the generator will not know that it's an abstract class.

This commit seems to fix OSX support and passes on Travis. You can try to run tests/travis.bash on your local machine.

emoon commented 8 years ago

Ah. I didn't use the -d flag no. What is the exact command line I should use? (edit: nm, I see it now in the build script) I will try out the travis script. Thanks!

emoon commented 8 years ago

I still run into issues when trying this on my machine

C++ library name: Qt5Core
Detecting Qt directories...
Executing command: "qmake" "-query" "QT_INSTALL_HEADERS"
/Users/danielcollin/Qt5.7.0/include
QT_INSTALL_HEADERS = "/Users/danielcollin/Qt5.7.0/include"
Executing command: "qmake" "-query" "QT_INSTALL_LIBS"
/Users/danielcollin/Qt5.7.0/lib
QT_INSTALL_LIBS = "/Users/danielcollin/Qt5.7.0/lib"
Building without Qt doc data (no env var: QT5CORE_DOC_DATA)
Parsing C++ headers.
clang version 3.8.0 (tags/RELEASE_380/final)
Initializing clang...
clang arguments: ["-fPIC", "-fcxx-exceptions", "-std=gnu++11", "-Xclang", "-detailed-preprocessing-record", "-I", "/Users/danielcollin/Qt5.7.0/include", "-I", "/Users/danielcollin/Qt5.7.0/lib/QtCore.framework/Headers", "-isystem", "/Users/danielcollin/clang-3.8/lib/clang/3.8.0/include", "-F", "/Users/danielcollin/Qt5.7.0/lib"]
Diagnostics:
/Users/danielcollin/clang-3.8/include/c++/v1/cstddef:43:15: fatal error: 'stddef.h' file not found
thread 'main' panicked at 'terminated because of clang errors', src/cpp_parser.rs:172
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Riateche commented 8 years ago

Generator commands should be like that:

cargo run -- -s $REPOS/qt_core -o $OUT/qt_core
cargo run -- -s $REPOS/qt_gui -o $OUT/qt_gui -d $OUT/qt_core
cargo run -- -s $REPOS/qt_widgets -o $OUT/qt_widgets -d $OUT/qt_core $OUT/qt_gui

Does /Users/danielcollin/clang-3.8/lib/clang/3.8.0/include dir exist? Does it contain stddef.h?

emoon commented 8 years ago

Yeah, it's there. Maybe the issues is that -isystem is used instead of -I ?

Riateche commented 8 years ago

IIRC, it didn't work for me until I replaced -I with -isystem. You can tweak it at src/cpp_parser.rs:143 and see what happens. Also try to check if libclang from the same directory is used and not some system-wide installation.

I don't fully understand why these headers are not visible by default. They are visible to clang binary, but not libclang for some reason. I found that this issue is mentioned a lot, but I didn't find any canonical solution.

emoon commented 8 years ago

Setting -I make it work. I now run into

/Users/danielcollin/Qt5.7.0/lib/QtCore.framework/Headers/qsystemdetection.h:95:12: fatal error: 'TargetConditionals.h' file not found

TargetConditionals.h seems to be some Mac specific header in the sdk that can be found

MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/TargetConditionals.h

I'm unsure how the script can pick up that path though unless travis sets that up somehow.

Riateche commented 8 years ago

On my system Qt Creator shows that it uses TargetConditionals.h from /usr/include directory. Try to add -I /usr/include.

emoon commented 8 years ago

Hum.. I don't even have have /usr/include dir on my system.

Riateche commented 8 years ago

I've found this: http://superuser.com/a/1014872/40045 It seems that you have XCode without command line developer tools, while I have command line developer tools without XCode. Maybe you can install these tools and it will start working. I'm totally unfamiliar with OS X ecosystem, so I'm not sure if it has any drawbacks.

emoon commented 8 years ago

Will try!

emoon commented 8 years ago

Ok.. now it's running and doing stuff!

emoon commented 8 years ago

Seems to work fine now.

Riateche commented 8 years ago

Great! Check if it works with original version (with "-isystem") with command line tools installed. If not, please submit a PR so that we can see what Travis thinks about it.

emoon commented 8 years ago

Seems to work fine without it so all good.