I am trying to compile Linux on Eclipse. I am compiling for x86 only but want to use my tool chain. I created a project as "File -> C Project -> Linux gcc" and gave the location of my Linux kernel. I right clicked on "Project -> Properties -> C/C++ build -> Settings" and changed GCC C compiler and linker and include path to my toolchain.
On C/C++ build, I replaced make with below command
make ARCH=x86 CC=/home/poky/build/tmp/sysroots/i686-linux/usr/bin/corei7-64-poky-linux/x86_64-poky-linux-
Now when I try to build, I am getting below error
make ARCH=x86 CC=/home/poky/build/tmp/sysroots/i686-linux/usr
/bin/corei7-64-poky-linux/x86_64-poky-linux- all
Building file: ../virt/kvm/arm/arch_timer.c
Invoking: GCC C Compiler
/home/poky/build/tmp/sysroots/i686-linux/usr/bin/corei7-64-
poky-linux/x86_64-poky-linux-gcc -I/home/poky/build/tmp/sysroots
/i686-linux/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"virt/kvm/arm/arch_timer.d" -MT"virt/kvm/arm/arch_timer.d" -o "virt/kvm/arm/arch_timer.o" "../virt/kvm/arm/arch_timer.c"
../virt/kvm/arm/arch_timer.c:19:23: fatal error: linux/cpu.h: No such file or directory
#include <linux/cpu.h>
^
compilation terminated.
make: *** [virt/kvm/arm/arch_timer.o] Error 1
How can I cross compile Linux kernel on Eclipse? I want to use my own toolchain.
Your compiling works as it should but it seems that you haven't yet added all necessary include paths.
As the error msg already mentions, the compiler can't find linux/cpu.h
You can add additional include paths at: Project->Properties->C/C++ General-> Paths and Symbols
Related
I am compiling my binary on a Raspberry device but when I move it to another one I get the following error:
./iot-relay
./iot-relay: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory`
I've come to the conclusion that compiling a fully statically linked binary may help so I start reading about this here
Adding the target that I guess is appropriate:
rustup target add armv7-unknown-linux-musleabihf
And attempting to compile:
cargo build --release --target armv7-unknown-linux-musleabihf
It compiles most of the stuff but then:
error: failed to run custom build command for `paho-mqtt-sys v0.3.0`
Caused by:
process didn't exit successfully: `/home/pi/rust/iot-relay/target/release/build/paho-mqtt-sys-9d34dbf9179b933d/build-script-build` (exit code: 101)
--- stdout
debug:Running the bundled build for Paho C
cargo:rerun-if-changed=build.rs
running: "cmake" "/home/pi/.cargo/registry/src/github.com-1285ae84e5963aae/paho-mqtt-sys-0.3.0/paho.mqtt.c/" "-DPAHO_BUILD_SHARED=off" "-DPAHO_BUILD_STATIC=on" "-DPAHO_ENABLE_TESTING=off" "-DPAHO_WITH_SSL=on" "-DCMAKE_INSTALL_PREFIX=/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_C_COMPILER=arm-linux-musleabihf-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_CXX_COMPILER=arm-linux-musleabihf-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_ASM_COMPILER=arm-linux-musleabihf-gcc" "-DCMAKE_BUILD_TYPE=Release"
-- The C compiler identification is unknown
-- Configuring incomplete, errors occurred!
See also "/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out/build/CMakeFiles/CMakeOutput.log".
See also "/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out/build/CMakeFiles/CMakeError.log".
--- stderr
fatal: not a git repository (or any of the parent directories): .git
CMake Error at CMakeLists.txt:21 (PROJECT):
The CMAKE_C_COMPILER:
arm-linux-musleabihf-gcc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
thread 'main' panicked at '
command did not execute successfully, got: exit code: 1
build script failed, must exit now', /home/pi/.cargo/registry/src/github.com-1285ae84e5963aae/cmake-0.1.44/src/lib.rs:885:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
How can I fix this and get my statically linked binary that would work on my other Raspberry? Unfortunately, the one that can't run the binary is a custom one and has some custom software that prevents me from doing system updates so I am hoping to pack everything required into the binary on the one over which I do have control.
This is cargo looking to follow build instructions to for a C dependency and not finding the gcc supporting the specified toolchain. You may need to find the correct location and name for your gcc targeting your environment (CC=). If you don't have a cross compiler for that target and musl libc combo, you may have to build one. See the link below for info on how to do that.
https://wiki.musl-libc.org/getting-started.html
I'm trying to cross compile to an arm development board. The makefile is invoking the native (x86) compiler, but passing it options that only make sense to an ARM compiler. I have the beginning of my make file as:
ARCH = arm
CC = arm-Linux-gnueabi-gcc
The error I keep getting is: arm-linux-gnueabi-gcc error unrecognized command line option '-m64'
I'm using the Visual C++ for Linux plugin. I can run a basic Hello world without problems. My actual project uses a .lib. It compiles fine but I get an error during linking (this is copied from Visual Studio's output pane):
ClCompile:
Starting remote build
Compiling sources:
Invoking g++
g++ -c -x c++ /home/devbox/projects/LinuxProgServ/LinuxProgServ/main.cpp -I /home/devbox/projects/LinuxProgServ/include/libuv -I /home/devbox/projects/LinuxProgServ/../include/lubuntu -I "/home/devbox/projects/LinuxProgServ/../include/lubuntu/x86_64-linux-gnu" -g2 -gdwarf-2 -o "/home/devbox/projects/LinuxProgServ/obj/x64/Debug/main.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O0 -fno-strict-aliasing -fno-omit-frame-pointer -fthreadsafe-statics -fexceptions -frtti -std=c++11
main.cpp
Done compiling '/home/devbox/projects/LinuxProgServ/LinuxProgServ/main.cpp'
Link:
Linking objects
Invoking ld
g++ -o "/home/devbox/projects/LinuxProgServ/bin/x64/Debug/LinuxProgServ.out" -Wl,--no-undefined /home/devbox/projects/LinuxProgServ/obj/x64/Debug/main.o -llibuv.lib
/usr/bin/ld: cannot find -llibuv.lib
collect2: error: ld returned 1 exit status
libuv.lib is specified in Project Properties>Linker>Input>Library Dependencies. I tried the following without success:
Copy the lib to /home/devbox/projects/lib and add that directory to
the linker command with -L, both using Visual Studio's additional
library folder field and directly in the Additional command line
options field. This results in the same final command.
Copy the lib to the output directory and set it to be copied
Add the local Windows path to Visual Studio's additional library folders
Add the linux path from #1 to Visual Studio's additional library folders
Try with another library
I made the same project but for Windows just to be sure and it works.
Am I missing something? Obviously I could just run the commands myself or use any variant of *make but that's not the point.
When you pass a library to g++ with -l, g++ helpfully prefixes the name you give with lib then looks for a file of that name with a .so or .a extension on the library search path. By convention, shared libraries (dlls) have the .so extension and static libraries the .a extension.
The route of least resistance would be to build your library with the .a extension, i.e. libuv.a then specify it to the VCLinux project library dependencies as uv. And specify the library search path with -L, as you do in your step 1.
Alternatively, you can put the full path of the library on the g++ link command line, without -l prefix, i.e. /home/devbox/projects/lib/libuv.lib and g++ will use it in the same way it uses other object files. Set via Linker/All Options/Additional Options.
Update: on reflection, this second approach won't work. Although g++ (gcc) will accept the library as an input when specified with its fully qualified path, the library must appear after the program object files for references to be resolved. Unfortunately there is no control over positioning of Additional Options in VCLinux which always puts them at the front of the parameter list on the g++ command line, i.e. before the object file(s). :(
And, at the risk of stating the obvious, the library must be built on Linux with g++ and be located on a path visible to g++ when linking your program.
This is a most vexing issue. When I run my makefile I see two sysroot in the output:
ubuntu#ubuntu:~/Desktop/LatestAndroidstuff/CmE_source_DAL_1.7_3564/CmCompact$ make
platform/wince/WibuCmHID/rules.mak:31: WibuCmHID only for Windows CE
/home/ubuntu/my-android-toolchain/bin//arm-linux-androideabi-gcc -I./ -I./external/hidapi/include -Os -std=c99 -Wall -Wextra -fno-short-enums -fno-strict-aliasing --sysroot=/home/ubuntu/my-android-toolchain/sysroot --sysroot=/home/ubuntu/android-ndk-r13b/platforms/android-14/arch-arm -o obj/release/android/armeabi-v7a/static/w_refcount.o -c base/w_refcount.c
In file included from base/w_refcount.c:29:0:
./base/w_define.h:31:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
rules.mak:54: recipe for target 'obj/release/android/armeabi-v7a/static/w_refcount.o' failed
make: *** [obj/release/android/armeabi-v7a/static/w_refcount.o] Error 1
If I edit the failing command and remove the extra sysroot (the second one), it works.
/home/ubuntu/my-android-toolchain/bin//arm-linux-androideabi-gcc -I./ -I./external/hidapi/include -Os -std=c99 -Wall -Wextra -fno-short-enums -fno-strict-aliasing --sysroot=/home/ubuntu/my-android-toolchain/sysroot --sysroot=/home/ubuntu/android-ndk-r13b/platforms/android-14/arch-arm -o obj/release/android/armeabi-v7a/static/w_refcount.o -c base/w_refcount.c
Problem is, I have looked all over the makefile. The makefile is simple enough:
WBSMAK_ANDROID_NDK_HOME=/home/ubuntu/android-ndk-r13b
SYSROOT=/home/ubuntu/my-android-toolchain/sysroot
ANDROID_TOOLCHAIN_DIR=/home/ubuntu/my-android-toolchain/bin/
WBSMAK_ANDROID_CC=${ANDROID_TOOLCHAIN_DIR}/arm-linux-androideabi-gcc
WBSMAK_ANDROID_LD=${ANDROID_TOOLCHAIN_DIR}/arm-linux-androideabi-ld
WBSMAK_ANDROID_AR=${ANDROID_TOOLCHAIN_DIR}/arm-linux-androideabi-ar
WBSMAK_ANDROID_RANLIB=${ANDROID_TOOLCHAIN_DIR}/arm-linux-androideabi-ranlib
SHELL := /bin/bash
AR := WBSMAK_ANDROID_AR
CC ?= WBSMAK_ANDROID_CC
LD ?= WBSMAK_ANDROID_LD
RANLIB := WBSMAK_ANDROID_RANLIB
In order to make the file pick up sysroot:
CFLAGS_ARCH := --sysroot=${SYSROOT}
But there is no mention at all in the makefile about that other second sysroot nor that path that shows up. Also, I looked and made sure it's not picking up an environment variable.
ubuntu#ubuntu:~/my-android-toolchain$ printenv | grep SYSROOT
ANDROID_SYSROOT=
LINARO_SYSROOT=/home/ubuntu/linaro-toolchain-4.6/arm-unknown-linux-gnueabi/sysroot
SYSROOT=/home/ubuntu/my-android-toolchain/
The environment sysroot it pointed to where I want it.
If I move the Android NDK folder and all its stuff out of the path, that is nowhere in the makefile, then I get the error. If I have the folder where the extra sysroot is, then the library compiles and links, but it crashes on the Android device, which is Android 21, not 14. I don't know why it's always Android 14. Could I be missing some setting somewhere? Perhaps when I created the standalone tools using make-standalone-toolchain.sh something hardcoded went in so the calls to /home/ubuntu/my-android-toolchain/bin/arm-linux-androideabi-gcc always searches for the android-14 path?
Very vexing problem. I have been all over the makefile. I don't know why the gcc keeps picking up that android 14 sysroot. Could I be only providing for the compilation but the linking is pulling up a default sysroot?
Alright the issue appears to have been a carefully sidelines .mak file in a subfolder that was looking for a string in a string of an existing field and on finding that, was using ANDROID_ARCH for the --sysroot in the actual gcc call. But to the credit of who wrote it, it did have the other -march setting needed for proper compile and linking of the android native module.
Moral of the story: always surf around the folders and take a glance at everything.
(of course my app still crashes but that's another matter to find that out... )
If one installs an R package that requires compilation via
R CMD INSTALL package.tar.gz
from the bash, R uses by default the gcc compiler. It happened now that my R-package throws a warning on Cran with a 'clang' compiler setup, that doesn't appear using the gcc compiler.
In order to reproduce the warning now on my local machine, I would like to adjust the local compiler settings to those used on the Cran-check servers.
I found out that it should be possible to change the R default compiler by creating a Makevars.in file somewhere in the home folder, but I cannot find where it has to be located and what has to be written there in order to make R to use 'clang' with certain warning flags enabled instead of 'gcc'.
Has anybody already switched on his/her Linux system the R default compiler from gcc to clang and could give me a hint how to do that?
My favourite method (and I think I detailed that here before) is to use the file ~/.R/Makevars where I set
CFLAGS += -O3 -Wall -pipe -pedantic -std=gnu99
CXXFLAGS += -O3 -Wall -pipe -Wno-unused -pedantic
#VER=-4.6
#VER=-4.7
VER=-4.8
CC=ccache gcc$(VER)
CXX=ccache g++$(VER)
SHLIB_CXXLD=g++$(VER)
FC=ccache gfortran
F77=ccache gfortran
MAKE=make -j8
#CXX=clang++
#CC=clang
and more as it also allows you to switch to clang++ instead of g++ and more.
I use ccache here too in order to accelerate repeated builds -- very useful for R packages where you may alter the package code but not the src/ files.
An alternative approach would a shell-script wrapper in which you set CC, CXX and everything else you want to modify.