Cargo/Rust build time error - with target ```armv7-unknown-linux-gnueabi``` - rust

A simple program
// main.rs
//
fn main() {
println!("Hello World!");
}
Built with target armv7-unknown-linux-gnueabi and get build time error
$rustc --target armv7-unknown-linux-gnueabi main.rs
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "main.main.bb83c76b-cgu.0.rcgu.o" "main.main.bb83c76b-cgu.1.rcgu.o" "main.main.bb83c76b-cgu.2.rcgu.o" "main.main.bb83c76b-cgu.3.rcgu.o" "main.main.bb83c76b-cgu.4.rcgu.o" "main.main.bb83c76b-cgu.5.rcgu.o" "main.main.bb83c76b-cgu.6.rcgu.o" "main.main.bb83c76b-cgu.7.rcgu.o" "main.1nspxxkz83ziil5b.rcgu.o" "-Wl,--as-needed" "-L" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libstd-f877b6743fad9ce0.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libpanic_unwind-ca23a35fd6776e95.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libminiz_oxide-9b2325ccfefdae49.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libadler-78c636d1cefe1f53.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libobject-cd2a15b9c0cd0912.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libmemchr-87348818413b65dc.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libaddr2line-28914e0ca2a7cabd.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libgimli-edb9d7f286e86f79.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libstd_detect-08665724c4ec2083.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/librustc_demangle-a0fbe62ad5846784.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libhashbrown-f989e60894fc6d57.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/librustc_std_workspace_alloc-17d6e1a134fbbef9.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libunwind-15bfe40785c93f7b.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libcfg_if-8452e19dfd17f32a.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/liblibc-ff6e3684a369debc.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/liballoc-dc146827e3238c67.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/librustc_std_workspace_core-7fa8d80aeaa09d86.rlib" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libcore-3ed097770b462522.rlib" "-Wl,--end-group" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib/libcompiler_builtins-97fd0602acb09555.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabi/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: main.main.bb83c76b-cgu.0.rcgu.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: main.main.bb83c76b-cgu.0.rcgu.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: main.main.bb83c76b-cgu.0.rcgu.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: main.main.bb83c76b-cgu.0.rcgu.o: Relocations in generic ELF (EM: 40)
main.main.bb83c76b-cgu.0.rcgu.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
error: aborting due to previous error

looks like armv7-unknown-linux-gnueabi is unavailable yet, so no armv7-unknown-linux-gnueabi-gcc, refer to https://github.com/rust-lang/rust/issues/105406

Related

gcc10 compile c++ code and link to libraries compiled by gcc11

I am using gcc10 for my code. My system installed the official libraries compiled by gcc11.
OS:archlinux
compiler: gcc-10
Archlinux updated their official compiler to gcc-11.
When I use gcc10 to compile my code and link to the libraries compiled by gcc11, it shows the following error message:
/usr/bin/ld: /usr/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_release()#CXXABI_1.3.13'
/usr/bin/ld: /usr/lib/libQt5Widgets.so.5.15.2: undefined reference to `std::__throw_bad_array_new_length()#GLIBCXX_3.4.29'
/usr/bin/ld: /usr/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_addref()#CXXABI_1.3.13'
It seems related to stdc++ libraries. What should I do?
------------------------------------------
I tried to use gcc11 to compile everything including the libraries. It is fine to compile the libraries that I need.
When I compile my code, it shows the error messages:
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<double*>::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<ceres::Grid2D<double, 1, true, true> >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<ceres::BiCubicInterpolator<ceres::Grid2D<double, 1, true, true> > >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<std::shared_ptr<Keyframe> >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<unsigned long>::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o:/usr/include/c++/11.1.0/ext/new_allocator.h:110: more undefined references to `std::__throw_bad_array_new_length()' follow
/usr/bin/ld: /usr/local/lib/libopencv_core.so.3.4.15: undefined reference to `std::__exception_ptr::exception_ptr::_M_release()#CXXABI_1.3.13'
/usr/bin/ld: /usr/lib/libvtkRenderingCore.so.1: undefined reference to `std::__istream_extract(std::istream&, char*, long)#GLIBCXX_3.4.29'
/usr/bin/ld: ../lib/libdataset_inputstream.so: undefined reference to `std::__throw_bad_array_new_length()#GLIBCXX_3.4.29'
/usr/bin/ld: /usr/local/lib/libopencv_core.so.3.4.15: undefined reference to `std::__exception_ptr::exception_ptr::_M_addref()#CXXABI_1.3.13'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/depth_camera_slam.dir/build.make:351: ../bin/depth_camera_slam] Error 1
make[1]: *** [CMakeFiles/Makefile2:804: CMakeFiles/depth_camera_slam.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Is it related to stdc++ lib? or my compiler? I think my code is fine because I can compile it on my old machine (archlinux but the compiler is gcc10).
-------------------------------------
I can't uninstall gcc10 because I am using CUDA11 which depends on gcc10.

Errors with /usr/bin/ld compiling Fortran 77 code

Code: https://github.com/CGS-GIS/GPSPACE
OS: Linux 5.6.15-arch1-1 #1 SMP PREEMPT x86_64 GNU/Linux
Compiler: gfortran - GNU Fortran (GCC) 10.1.0
Command: gfortran -std=legacy gpspace.f */*.F -o gpsppp
Output:
/usr/bin/ld: /tmp/ccIvkFdn.o: in function `vmfintrp_':
gpspace.f:(.text+0x27fb7): undefined reference to `vmf1_ht_'
/usr/bin/ld: gpspace.f:(.text+0x27fea): undefined reference to `vmf1_'
/usr/bin/ld: /tmp/ccIvkFdn.o: in function `bodyt_':
gpspace.f:(.text+0x34ae9): undefined reference to `dehanttideinel_'
/usr/bin/ld: /tmp/ccIvkFdn.o: in function `rderp_':
gpspace.f:(.text+0x36103): undefined reference to `iers_cmp_2015_'
/usr/bin/ld: gpspace.f:(.text+0x3617f): undefined reference to `iers_cmp_2015_'
/usr/bin/ld: gpspace.f:(.text+0x3622e): undefined reference to `iers_cmp_2015_'
/usr/bin/ld: /tmp/ccIvkFdn.o: in function `rdmet_':
gpspace.f:(.text+0x367bd): undefined reference to `gpt_'
/usr/bin/ld: /tmp/ccIvkFdn.o: in function `MAIN__':
gpspace.f:(.text+0xa750f): undefined reference to `gpt_'
/usr/bin/ld: gpspace.f:(.text+0xacce9): undefined reference to `gmf_'
/usr/bin/ld: /tmp/cc9KTZfn.o: in function `oloadn_':
OLOADN.F:(.text+0x242): undefined reference to `admint_'
/usr/bin/ld: OLOADN.F:(.text+0x3ac): undefined reference to `admint_'
/usr/bin/ld: OLOADN.F:(.text+0x516): undefined reference to `admint_'
/usr/bin/ld: OLOADN.F:(.text+0x976): undefined reference to `recurs_'
/usr/bin/ld: OLOADN.F:(.text+0x9ae): undefined reference to `recurs_'
/usr/bin/ld: OLOADN.F:(.text+0x9e6): undefined reference to `recurs_'
collect2: error: ld returned 1 exit status
No clue what the problem is...

BZIP2 linking error with Cygwin64

I encounter the following linking error when attempting to use in Cygwin64. My PATH accounts for the location of libbz2.a and libbz2.dll.
$ gcc -lbz2 bzlibExample.c -o bzlibExample
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x18b): undefined reference to `BZ2_bzWriteOpen'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x18b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteOpen'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x1ef): undefined reference to `BZ2_bzWrite'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x1ef): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWrite'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x233): undefined reference to `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x233): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x2bb): undefined reference to `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x2bb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteClose'
collect2: error: ld returned 1 exit status
Any assistance is appreciated.

How do I FFI a CUDA application on Haskell?

I've ported a Haskell application to CUDA in order to accelerate it. Now, I have a .cu file which I want to use from Haskell as an API. I've managed to FFI C files easily following the tutorials, but I'm not sure how this applies to CUDA/nvcc. How do I do it?
For completion, this is what I get trying to treat the .cu as a normal .c file:
vh:CUDA apple1$ nvcc hello.cu -c -o hello.o
vh:CUDA apple1$ ghc test.hs -o test hello.o
Linking test ...
Undefined symbols for architecture x86_64:
"___cudaRegisterFatBinary", referenced from:
__sti____cudaRegisterAll_40_tmpxft_00002168_00000000_7_hello_cpp1_ii_f33df8d2() in hello.o
"___cudaRegisterFunction", referenced from:
__nv_cudaEntityRegisterCallback(void**) in hello.o
"___cudaUnregisterFatBinary", referenced from:
__cudaUnregisterBinaryUtil() in hello.o
"_cudaConfigureCall", referenced from:
render(Renderer_*) in hello.o
"_cudaFree", referenced from:
renderer_free(Renderer_*) in hello.o
"_cudaLaunch", referenced from:
cudaError cudaLaunch<char>(char*) in hello.o
"_cudaMalloc", referenced from:
renderer_init(Renderer_*, float, float, float, float, float) in hello.o
"_cudaMemcpy", referenced from:
renderer_init(Renderer_*, float, float, float, float, float) in hello.o
render(Renderer_*) in hello.o
"_cudaSetupArgument", referenced from:
__device_stub__Z4walk6float3PiS_S_S_S_S0_(float3&, int*, float3&, float3&, float3&, float3&, int*) in hello.o
"_hello", referenced from:
_r3yw_info in test.o
_c3Ib_info in test.o
_c3Il_info in test.o
(maybe you meant: _Main_hello_closure, _Main_hello_info )
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And that is my Haskell file:
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign.C
import Foreign.Ptr (Ptr,nullPtr)
foreign import ccall "hello" hello :: IO ()
main = hello
I managed to solve it by adding extern "C" to all functions on hello.cu:
-- hello.cu
extern "C"
void hello();
Compiling the CUDA file with:
nvcc -c hello.cu
And the Haskell file with:
ghc --make test.hs -o test hello.o -L/usr/local/cuda/lib -optl-lcudart

Cannot use g++ for compiling

right now I try to use a opensource tool called "GAUL" where some genetic algorithms are implemented. By compiling the example files I figured out that I can only compile these data via using gcc but not g++. E.x.:
1) Using gcc -I /usr/local/include/ -c wildfire_threat.c -o test.o
gcc** -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm
works also the combination
gcc -I /usr/local/include/ -c wildfire_threat.c -o test.o
g++ -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm
But 2) Using
g++ -I /usr/local/include/ -c wildfire_threat.c -o test.o
g++ -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm
I get the following error messages:
test.o: In function `wildfire_simulation(int*, bool)':
wildfire_threat.c:(.text+0x52): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0x74): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_score(population_t*, entity_t*)':
wildfire_threat.c:(.text+0xb55): undefined reference to `ga_entity_set_fitness(entity_t*, double)'
test.o: In function `wildfire_seed(population_t*, entity_t*)':
wildfire_threat.c:(.text+0xb86): undefined reference to `random_boolean()'
wildfire_threat.c:(.text+0xbb9): undefined reference to `random_boolean_prob(double)'
wildfire_threat.c:(.text+0xc18): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0xc25): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0xc92): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_mutate_flip(population_t*, entity_t*, entity_t*)':
wildfire_threat.c:(.text+0xd41): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_crossover(population_t*, entity_t*, entity_t*, entity_t*, entity_t*)':
wildfire_threat.c:(.text+0xe25): undefined reference to `random_boolean()'
wildfire_threat.c:(.text+0xe37): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0xff0): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_ga_callback(int, population_t*)':
wildfire_threat.c:(.text+0x11bc): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x11c4): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x11ef): undefined reference to
`ga_population_score_and_sort(population_t*)'
wildfire_threat.c:(.text+0x1206): undefined reference to `ga_fitness_mean_stddev(population_t*, double*, double*)'
wildfire_threat.c:(.text+0x122b): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1233): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x1268): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1270): undefined reference to `ga_entity_get_fitness(entity_t*)'
test.o: In function `main':
wildfire_threat.c:(.text+0x12b0): undefined reference to `random_seed(unsigned int)'
wildfire_threat.c:(.text+0x12dd): undefined reference to `ga_select_two_roulette_rebased(population_t*, entity_t**, entity_t**)'
wildfire_threat.c:(.text+0x12e6): undefined reference to `ga_select_one_roulette_rebased(population_t*, entity_t**)'
wildfire_threat.c:(.text+0x132e): undefined reference to `ga_genesis_integer(int, int, int, bool (*)(int, population_t*), bool (*)(int, entity_t*), void (*)(void*), void (*)(void*), bool (*)(population_t*, entity_t*), bool (*)(population_t*, entity_t*), entity_t* (*)(population_t*, entity_t*), bool (*)(population_t*, entity_t**), bool (*)(population_t*, entity_t**, entity_t**), void (*)(population_t*, entity_t*, entity_t*), void (*)(population_t*, entity_t*, entity_t*, entity_t*, entity_t*), void (*)(population_t*, entity_t*), void*)'
wildfire_threat.c:(.text+0x135c): undefined reference to `ga_population_set_parameters(population_t*, ga_scheme_type_t, ga_elitism_type_t, double, double, double)'
wildfire_threat.c:(.text+0x136d): undefined reference to `ga_evolution_threaded(population_t*, int)'
wildfire_threat.c:(.text+0x137e): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1386): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x13b5): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1434): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1528): undefined reference to `ga_extinction(population_t*)'
collect2: ld returned 1 exit status
Can anyone explain this to me mystery and how I can avoid to use gcc since this brings problems with remaining source code which I want to embed?
Your third party C library probably lacks extern "C" declarations in its headers. To work around this without modifying the third party headers you can do something like this in your C++ source wherever you #include the relevant third party headers:
extern "C" {
#include "gaul.h" // note: I'm just guessing the names of the
#include "gaul_utils.h" // actual header files here...
}
You should compile C source with a C compiler and C++ source with a C++ compiler. In the particular case, the GAUL library is written in C and its headers are not suitable for inclusion in C++ compilation - they lack extern "C", so when you compile as C++, the function are declared with C++ linkage and, of course, cannot be found in the C-compiled library.

Resources