I am trying to build a gtk-4 GUI application with the Rust in VScode, but I am unable to because I can't build my project. What could be the problem? How do I fix it?
Here's the error
fatal error LNK1181: cannot open input file 'gobject-2.0.lib'
My Cargo.toml
[package]
name = "my-gtk-app"
version = "0.1.0"
edition = "2021"
[dependencies]
gtk = { version = "0.4.7", package = "gtk4", features = ["v4_6"]}
Building the project as an administrator fixed the problem.
Related
I'm starting a new Rust project and included the ggez package in Cargo.toml
[package]
name = "Project"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ggez = "0.8.1"
However, when I run cargo build, I get the following error
error: failed to download `raw-window-handle v0.4.3`
Caused by:
unable to get packages from source
Caused by:
failed to parse manifest at `C:\Users\scout\.cargo\registry\src\github.com-1ecc6299db9ec823\raw-window-handle-0.4.3\Cargo.toml`
Caused by:
could not parse input as TOML
Caused by:
TOML parse error at line 1, column 1
|
1 |
| ^
Unexpected ``
Expected key or end of input
How can I remedy this issue?
I've tried including the raw-window-handle package manually, but I still get the same issue.
I am getting this error every time while running cargo build:
error: failed to select a version for the requirement `rand = "^0.9.0"`
candidate versions found which didn't match: 0.8.5, 0.8.4, 0.8.3, ...
location searched: crates.io index
required by package `guessing_game v0.1.0 (D:\Adwait\Rust\project\guessing_game)`
Cargo.toml looks like this:
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.9.0"
This error is caused because there is no version 0.9.0 available. Update it to 0.8.0. Cargo.toml should look like this.
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.0"
I experienced this myself, I believe the confusion is stemming from the tutorial on Rust mentioning 0.9.0 as an example to understand upgrading Rust crates.
I'm not sure why they chose that example, since it doesn't exist. Would be a better idea to do 0.7.x being upgraded to 0.8.0 if you're new to Rust and want to play around with upgrading Rust crates.
I have a simple Gtk app in Rust, but I get this error when compiling:
Package glib-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glib-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glib-2.0' found
And yes, I read Cannot compile gstreamer on Windows because it is missing glib-2.0, but it still doesn't contain all the information I need.
I put export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/ in /home/user/.profile (as shown in Can't Set Environment Variables in ~/.profile), and I also ran it directly in the Rust project directory, to no avail. I used that path because it seemed closest to the one in the Windows question, though there were many pkgconfig directories on the system, in various places.
Here is my Rust code:
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let window = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Show the window.
window.show();
});
app.run();
}
and here is Cargo.toml:
[package]
name = "gtk_test"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = { version = "0.2", package = "gtk4" }
So my question: where is the glib-2.0.pc file on a Linux? Is it under a different name, or does it have to be installed?
I've had the same issue on Fedora 36 ARM. I've installed libwebkitgtk, rust-gtk-sys-devel, libproxy-webkitgtk4, webkitgtk4, libsoup, libsoup-devel and webkitgtk4-devel and it started working. Some of libraries above may not be needed for your issue. For fedora the command is:
sudo dnf install libwebkitgtk rust-gtk-sys-devel libproxy-webkitgtk4 webkitgtk4 libsoup libsoup-devel webkitgtk4-devel
When I run the build command
cargo build-bpf --manifest-path=Cargo.toml --bpf-out-dir=dist/program
error: failed to download solana-frozen-abi v1.7.9
Caused by:
unable to get packages from source
Caused by:
failed to parse manifest at /home/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-frozen-abi-1.7.9/Cargo.toml
Caused by:
feature resolver is required
There have been people with similar issues but the cause was old rustc version. Mine looks ok
rustc --version
rustc 1.55.0-nightly (7c3872e6b 2021-06-24)
cargo --version
cargo 1.55.0-nightly (9233aa06c 2021-06-22)
My Cargo.toml file looks like
[package]
name = "test"
version = "0.0.1"
edition = "2018"
exclude = ["tests/**"]
[features]
no-entrypoint = []
test-bpf = []
[dependencies]
borsh = "0.8.2"
num-derive = "0.3"
num-traits = "0.2"
solana-program = "1.6.10"
spl-token = { version="3.1.1", features = [ "no-entrypoint" ] }
thiserror = "1.0"
[dev-dependencies]
solana-program-test = "1.6.10"
solana-sdk = "1.6.10"
[lib]
crate-type = ["cdylib", "lib"]
I have downloaded the metaplex rust code (exact same dependencies) and the build bpf command compiles successfully.
I have also tried running cargo clean which doesnt change anything.
I fixed it by updating to the latest version (1.7.9) of Solana (which is not the release version):
sh -c "$(curl -sSfL https://release.solana.com/v1.7.9/install)"
The same inputs from Cargo.toml do not mean the the Rust build will be repeatable on other machines — Cargo.lock contains the exact versions used. Additionally, cargo clean doesn't remove Cargo.lock
https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
So I set up GTK-rs for rust and I must have done something wrong because when I try to run my code it returns this error and I have no idea how to fix it:
fatal error LNK1181: cannot open input file 'gtk-3.lib'
I use Eclipse IDE if that will help.
Some more data that might help:
My environment variables are:
GTK_LIB_DIR=C:\msys64\mingw64\lib
PATH:
C:\msys64\mingw64\bin
C:\msys64\mingw64\include
My Cargo.toml file:
[package]
name = "myapp"
version = "0.1.0"
authors = ["author"]
edition = "2018"
[dependencies.gtk]
version = "0.9.2"
features = ["v3_16"]
[dependencies]
glib = "0.10.2"
gio = "0.9.1"
I used some modified sample code for testing:
#![allow(non_snake_case)]
extern crate gtk;
extern crate glib;
extern crate gio;
use gio::prelude::*;
use glib::clone;
use gtk::prelude::*;
// When the application is launched…
fn on_activate(application: >k::Application) {
// … create a new window …
let window = gtk::ApplicationWindow::new(application);
// … with a button in it …
let button = gtk::Button::with_label("Hello World!");
// … which closes the window when clicked
button.connect_clicked(clone!(#weak window => move |_| window.close()));
window.add(&button);
window.show_all();
}
fn main() {
// Create a new application
let app = gtk::Application::new(Some("com.github.gtk-rs.examples.basic"), Default::default())
.expect("Initialization failed...");
app.connect_activate(|app| on_activate(app));
// Run the application
app.run(&std::env::args().collect::<Vec<_>>());
}
I was having the same problem with "link.exe" when using gstreamer and gtk Rust bindings. Here's what I did to make my program compile.
Download Microsoft Build Tools and install the following in addition to the 'default' tools that are installed when checking the "C++ build tools".
MS Build Tools Options - credit https://github.com/rust-lang/rust/issues/44787
After the installation, make sure that "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC<VC Version>\bin\Hostx64\x64" is in your environment path.
Restart your pc and try compiling again. Hopefully it is going to work. However, if it still doesn't, I recommend uninstalling Rust from powershell
rustup self uninstall
And then reinstalling Rust from the rustup.exe in this way.
Run rustup.exe
When prompted with the install option, select "customize installation"
For default host triples option type
stable-x86_64-pc-windows-gnu
Press enter for 'default' options for the rest and continue installation.
Restart your pc and the program is definitely going to compile.