Skip to content
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

Using rgtk in other projects - Consider expanding "Use rgtk" section in readme? #66

Closed
jatcwang opened this issue Sep 9, 2014 · 8 comments

Comments

@jatcwang
Copy link

jatcwang commented Sep 9, 2014

I made some attempt to use rgtk for a test application. Here's what's in my Cargo.toml

[package]
name = "rgtk-test"
version = "0.0.1"
authors = []

[dependencies.rgtk]
path = "../tools/rgtk"

[[bin]]
name = "gtktest"

Here's a simple program involving an Entry and a ListBox

#![feature(globs)]
#![crate_type = "bin"]

extern crate rgtk;

use rgtk::*;
use rgtk::gtk::signals;

fn main() {
    gtk::init();
    println!("Major: {}, Minor: {}", gtk::get_major_version(), gtk::get_minor_version());
    let mut window = gtk::Window::new(gtk::window_type::TopLevel).unwrap();
    let mut frame = gtk::Frame::new(Some("")).unwrap();
    let mut _box = gtk::Box::new(gtk::orientation::Horizontal, 10).unwrap();
    let mut entry = gtk::Entry::new().unwrap();
    let mut list_box = gtk::ListBox::new().unwrap();
    let mut lb = gtk::Label::new("Hello World").unwrap();

    println!("test");


    frame.set_border_width(10);
    _box.set_border_width(5);
    entry.set_placeholder("An Entry with a placeholder !");
    list_box.add(&lb);
    window.set_title("Yeah a beautiful window with rgtk !");
    window.add(&frame);
    window.add(&list_box);

    window.connect(signals::DeleteEvent::new(|_|{
        gtk::main_quit();
        true
    }));

    frame.add(&_box);
    _box.add(&entry);
    _box.set_orientation(gtk::orientation::Vertical);

    window.show_all();
    gtk::main();
}

The build fails with the following message:

[jtcwang@localhost fruzzy-test]$ cargo build --verbose
     Running `rustc src/rgtk.rs --crate-name rgtk --crate-type rlib -g -C metadata=6be5e259f9f3b082 -C extra-filename=-6be5e259f9f3b082 --out-dir /home/jtcwang/proj/fruzzy-test/target/deps --dep-info /home/jtcwang/proj/fruzzy-test/target/.fingerprint/rgtk-6be5e259f9f3b082/dep-lib-rgtk -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/native/rgtk-6be5e259f9f3b082`
     Running `rustc src/gtktest.rs --crate-name gtktest --crate-type bin -g --out-dir /home/jtcwang/proj/fruzzy-test/target --dep-info /home/jtcwang/proj/fruzzy-test/target/.fingerprint/rgtk-test-704d8a0eee6b3521/dep-bin-gtktest -L /home/jtcwang/proj/fruzzy-test/target -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/native/rgtk-6be5e259f9f3b082 --extern rgtk=/home/jtcwang/proj/fruzzy-test/target/deps/librgtk-6be5e259f9f3b082.rlib`
       Fresh rgtk v0.0.1 (file:///home/jtcwang/proj/fruzzy-test)
   Compiling rgtk-test v0.0.1 (file:///home/jtcwang/proj/fruzzy-test)
src/gtktest.rs:16:24: 16:41 error: failed to resolve. Could not find `ListBox` in `rgtk::gtk`.
src/gtktest.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                         ^~~~~~~~~~~~~~~~~
src/gtktest.rs:16:24: 16:41 error: unresolved name `gtk::ListBox::new`.
src/gtktest.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                         ^~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `rgtk-test`.

Environment

Fedora 20, GTK 3.10, rustc 0.12.0-pre-nightly (09cebc25a 2014-09-07 00:31:28 +0000)

So it looks like ListBox is not present. However, if I put the same code into rgtktest.rs (which is inside rgtk/examples directory) and use make rgtktest, it compiles and runs fine. Seems like the make file is linking some additional dependencies which I suspect is librgtk_glue.o inside target/deps/.

So here's what I'm asking:

  1. Am I doing it right? How can I use rgtk in another project? Do I need to use a makefile?
  2. Should "Use rgtk" be expanded to include more information on this?

I'm more than happy to help expand the readme, but I'll need some guidance here to get things started.

Thanks!

@jeremyletang
Copy link
Owner

hey,

For the moment we have a Makefile and a cargo build in rgtk, the goal is to use cargo in a near futur.
The actual problem is that we need to provide the --cfg="SOME_GTK_VERSION" option to rustc to precise the gtk+ version that we would build, and we cannot pass --cfg to cargo.

So:

  1. You are doing it right but it cannot work for the moment, you can use rgtk in a projet using a Makefile.
  2. Yes, we can expand the use rgtk section from the read me. Feel free to open a pull request, and we can discuss about it.

Be warn, that rgtk is really incomplete for the moment, it miss a lot of Widget !

@jeremyletang
Copy link
Owner

this pull request should allow use to pass --cfg options to cargo et choose a given version of gtk to build: cargo pull request

@TobiasBales
Copy link
Contributor

Yes that seems to work.
When adding

[features]
GTK_3_12 = []
GTK_3_10 = []
GTK_3_8 = []
GTK_3_6 = []

to the Cargo.toml file you can activate the specific libraries in a projects dependencies.
I still got issues getting it to import ListBox but when running cargo build -v it passes the specified --cfg to rustc e.g. including rgtk using

[dependencies.rgtk]
path = "../rgtk"
features = ["GTK_3_12"]

the correct --cfg is passed

 cargo clean; cargo build -v;                                                                                                              
 Compiling rgtk v0.0.1 (file:///home/Projects/dpb)
 Running sh cargobuild.sh
 Running `rustc src/rgtk.rs --crate-name rgtk --crate-type rlib -g 
  --cfg feature="GTK_3_12"
  -C metadata=476e95e2cc311ce6
  -C extra-filename=-476e95e2cc311ce6
  --out-dir /home/Projects/dpb/target/deps
  --dep-info /home/Projects/dpb/target/.fingerprint/rgtk-476e95e2cc311ce6/dep-lib-rgtk
  -L /home/Projects/dpb/target/deps
  -L /home/Projects/dpb/target/deps
  -L /home/Projects/dpb/target/native/rgtk-476e95e2cc311ce6`

@TobiasBales
Copy link
Contributor

So I can now get cargo to pass --cfg GTK_3_12 to rustc but for me at least it still fails with

/home/Projects/dpb/src/main.rs:16:24: 16:41 error: failed to resolve. Could not find `ListBox` in             `rgtk::gtk`.
/home/Projects/dpb/src/main.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                                         ^~~~~~~~~~~~~~~~~
/home/Projects/dpb/src/main.rs:16:24: 16:41 error: unresolved name `gtk::ListBox::new`.
/home/Projects/dpb/src/main.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                                         ^~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

Any ideas what the issue might be?

@jeremyletang
Copy link
Owner

I have the same behaviour on my computer, I can't find where this come, it may be a problem with GTK_VERSION configuration.

@TobiasBales
Copy link
Contributor

I misread the cargo documentation.
Added a new pull request which finally works.

@TobiasBales
Copy link
Contributor

So I think this issue is fixed now, correct?

@jeremyletang
Copy link
Owner

Yep i thinks it's fixed now !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants