cargo comandline arguments parse minus float - rust

How to parse a minus float in cargo? like
#[test]
fn test1() {
let args: Vec<String> = env::args().collect();
println!("{:?}", args);
}
and run it with
cargo test --release test1 -- -1.0 --nocapture --exact
cargo test --release test1 -- '-1.0' --nocapture --exact
cargo test --release test1 -- "-1.0" --nocapture --exact
cargo test --release test1 -- `-1.0` --nocapture --exact
/xxx/test_bin test1 -1.0 --nocapture
It says error: Unrecognized option: '1'
with rustc 1.64.0-nightly (6dba4ed21 2022-07-09)

Related

Threepenny GUI build fail

So I've been trying to install Threepenny GUI for a Haskell college assignment the last few hours without any avail. When stack attemps to build the 'snap-core' dependency, I get the following error:
snap-core > configure
snap-core > Configuring snap-core-1.0.5.0...
snap-core > build
snap-core > Preprocessing library for snap-core-1.0.5.0..
snap-core > Building library for snap-core-1.0.5.0..
snap-core > [ 1 of 18] Compiling Snap.Internal.Debug
snap-core > [ 2 of 18] Compiling Snap.Types.Headers
snap-core > [ 3 of 18] Compiling Snap.Internal.Http.Types
snap-core >
snap-core > src\Snap\Internal\Http\Types.hs:1285:11: error:
snap-core > * Variable not in scope:
snap-core > parseTime :: TimeLocale -> t0 -> String -> Maybe UTCTime
snap-core > * Perhaps you meant `parseTimeM' (imported from Data.Time.Format)
snap-core > |
snap-core > 1285 | prs = parseTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S GMT"
snap-core > | ^^^^^^^^^
Progress 1/4
-- While building package snap-core-1.0.5.0 (scroll up to its section to see the error) using:
C:\Users\User\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.6.3.0_ghc-9.2.5.exe --verbose=1 --builddir=.stack-work\dist\8a54c84f build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
I have tried building the dependencies of snap-core with 'stack build --dependencies-only snap-core' with no avail. I've also tried to build the 'time' package on it's own with no avail either. My stack version is up to date also. Any ideas..?

Running LLC from rust results in undefined reference to `main' for linking with gcc

Consider the hello world in LLVM-IR
#.str = internal constant [14 x i8] c"hello, world\0A\00"
declare i32 #printf(i8*, ...)
define i32 #main(i32 %argc, i8** %argv) nounwind {
entry:
%tmp1 = getelementptr [14 x i8], [14 x i8]* #.str, i32 0, i32 0
%tmp2 = call i32 (i8*, ...) #printf( i8* %tmp1 ) nounwind
ret i32 0
}
When I nor launch a llc process from rust:
use std::process::Command;
fn main() {
Command::new("/usr/lib/llvm-8/bin/llc")
.env_clear()
.arg("test.bc")
.arg("-o")
.arg("test.s")
.output()
.expect("failed to execute process");
}
I can not link the resulting test.s with gcc gcc test.s -no-pie -o test:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function _start':
(.text+0x20): undefined reference tomain'
collect2: error: ld returned 1 exit status
But when I ran llc direct in the terminal:
env -i /usr/lib/llvm-8/bin/llc test.bc -o test.s
Everything works well.
Does someone know some details?

Issues while do_package: split_and_strip_files (arm-poky-linux-gnueabi-objcopy) fails

I'm trying to add lmdb to my yocto build. This is my recipe:
LIC_FILES_CHKSUM = "file://LICENSE;md5=153d07ef052c4a37a8fac23bc6031972"
SRC_URI = " \
https://github.com/LMDB/lmdb/archive/LMDB_${PV}.tar.gz \
"
SRC_URI[md5sum] = "0de89730b8f3f5711c2b3a4ba517b648"
SRC_URI[sha256sum] = "49d7b40949f2ced9bc8b23ea6a89e75471a1c9126537a8b268c318a00b84322b"
BBFILE_PRIORITY = "8"
inherit autotools-brokensep
S = "${WORKDIR}/lmdb-LMDB_${PV}/libraries/liblmdb"
do_install() {
install -d ${D}${bindir}
install -d ${D}${libdir}
install -d ${D}${includedir}
install -d ${D}${mandir}
sed -i 's:\$(prefix)/man:${mandir}:' Makefile
oe_runmake DESTDIR=${D} prefix=${prefix} manprefix=${mandir} install
}
It compiles fine but I get an error during do_package task:
ERROR: objcopy failed with exit code 256 (cmd was 'aarch64-poky-linux-objcopy' --only-keep-debug '/media/build/tmp/work/aarch64-poky-linux/lmdb/0.9.16-r0/package/usr/bin/mdb_copy' '/media/build/tmp/work/aarch64-poky-linux/lmdb/0.9.16-r0/package/usr/bin/.debug/mdb_copy'): aarch64-poky-linux-objcopy: Unable to recognise the format of the input file `/media/build/tmp/work/aarch64-poky-linux/lmdb/0.9.16-r0/package/usr/bin/mdb_copy'
I tried including INHIBIT_PACKAGE_STRIP = "1" in my bb file. But it throws other errors:
ERROR: runstrip: ''aarch64-poky-linux-strip' --remove-section=.comment --remove-section=.note --strip-unneeded '/media/build/tmp/work/aarch64-poky-linux/lmdb/0.9.16-r0/sysroot-destdir/usr/lib/liblmdb.so'' strip command failed with 1 (aarch64-poky-linux-strip: Unable to recognise the format of the input file `/media/build/tmp/work/aarch64-poky-linux/lmdb/0.9.16-r0/sysroot-destdir/usr/lib/liblmdb.so'
)
ERROR: QA Issue: Architecture did not match (183 to 62) on work/aarch64-poky-linux/lmdb/0.9.16-r0/packages-split/lmdb-dev/usr/lib/liblmdb.so [arch]
WARNING: QA Issue: /usr/lib/liblmdb.so_lmdb-dev contained in package lmdb-dev requires libpthread.so.0(GLIBC_2.3.2)(64bit), but no providers found in its RDEPENDS [file-rdeps]
ERROR: QA Issue: Architecture did not match (183 to 62) on work/aarch64-poky-linux/lmdb/0.9.16-r0/packages-split/lmdb/usr/bin/mdb_dump [arch]
I'm on poky 2.0.2.
The github link doesnt exist.
However you can skip qa packaging with
do_package_qa[noexec] = "1"

How to build when multiple source files in rootfs in embedded linux?

I have a simple c application
Ctest.c file
#include <stdio.h>
#include "new.h"
#include "new.c"
int main()
{
switching();
return 0;
}
and i have those new.c and new.h files.
new.h file as
void switching();
and my new.c file as
void switching(){
char grade ='B';
switch(grade){
case 'A':
printf("Excellent\n");
break;
case 'B':
printf("Super\n");
break;
case 'C':
printf("Well done\n");
break;
case 'D':
printf("You passed\n");
break;
case 'F':
printf("Better try again");
break;
default:
printf("invalid grade");
break;
}
printf("your grade is %c \n",grade);
}
When i try to use build commands in my embedded linux tool for compiling and generating a binary , building is failed and here is my changed make file for the application on rootfs.
make file for the app Ctest:
APP = Ctest
# Add any other object files to this list below
APP_OBJS = Ctest.o
APP_OBJS += new.o
all: build
build: $(APP)
$(APP): $(APP_OBJS)
$(CC) $(LDFLAGS) -o $# $(APP_OBJS) $(LDLIBS)
Here is my error log during compile time
DEBUG: Executing shell function do_compile
NOTE: make -j 4
ERROR: oe_runmake failed
aarch64-xilinx-linux-gcc --sysroot=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64 -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0=/usr/src/debug/Ctest/1.0-r0 -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64= -c -o Ctest.o Ctest.c
aarch64-xilinx-linux-gcc --sysroot=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64 -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0=/usr/src/debug/Ctest/1.0-r0 -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64= -c -o new.o new.c
new.c: In function 'switching':
new.c:5:13: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
printf("Excellent\n");
^~~~~~
new.c:5:13: warning: incompatible implicit declaration of built-in function 'printf'
new.c:5:13: note: include '<stdio.h>' or provide a declaration of 'printf'
new.c:24:5: warning: incompatible implicit declaration of built-in function 'printf'
printf("your grade is %c \n",grade);
^~~~~~
new.c:24:5: note: include '<stdio.h>' or provide a declaration of 'printf'
Ctest.c:33:17: fatal error: new.h: No such file or directory
#include "new.h"
^
compilation terminated.
make: *** [<builtin>: Ctest.o] Error 1
make: *** Waiting for unfinished jobs....
ERROR: Function failed: do_compile (log file is located at /home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0/temp/log.do_compile.19737)
i understood that i need to do changes in the make file or bitbake file that build the application ie., Ctest.bb file If so what are the changes? And I am using petalinux 2017.1
the bitbake file of the application is
#
# This file is the Ctest recipe.
#
SUMMARY = "Simple Ctest application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://Ctest.c \
file://new.c \
file://Makefile \
"
S = "${WORKDIR}"
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}${bindir}
install -m 0755 Ctest ${D}${bindir}
install -m 0755 new ${D}${bindir}
}
How can i give new.h file into the make file or do i need to change the bitbake file?
Your Ctest.c file includes new.c so you should not be trying to build new.o at all. Remove the line
APP_OBJS += new.o
and
install -m 0755 new ${D}${bindir}
You are not providing the new.h file in your SRC_URI. Change it to
SRC_URI = "file://Ctest.c \
file://new.c \
file://new.h \
file://Makefile \
"

How to you get verbose output from ld when using Cargo?

How do you get the ld linker to be verbose when you use Cargo? I've tried several things in .cargo/config, but without luck. What would the right settings be? When using gcc directly, I can just do -Wl,--verbose.
[build]
rustflags = [
"-C", "prefer-dynamic",
# "-Z", "pre-link-arg=-pthread",
"-C", "link-arg=-pthread",
"-C", "link-arg=-fopenmp",
# "-C", "link-arg=-LC:/Octave/Octave-4.2.1/lib64/gcc/x86_64-w64-mingw32/4.9.4",
# "-C", "link-arg=--sysroot=C:/Octave/Octave-4.2.1",
# "-Z", "pre-link-args=-LC:/Octave/Octave-4.2.1/lib",
# "-Z", "pre-link-args=-LC:\\Octave\\Octave-4.2.1\\lib",
# "-C", "link-arg=--verbose",
# "-C", "link-arg=-v",
# "-C", "link-arg=-Wl,--verbose",
# "-Z", "print-link-args",
]
[target.x86_64-pc-windows-gnu]
linker = "C:/Octave/Octave-4.2.1/bin/gcc.exe"
# rustflags = [
# "-C", "link-arg=-Wl,--verbose",
# ]
# [term]
# verbose = true
I'm trying to build a library for Octave with Rust.
Found the answer: https://github.com/rust-lang/rust/issues/38206
export RUSTC_LOG=rustc_codegen_ssa::back::link=info

Resources