I have run gcc cross compiler from ubuntu(x86) to arm. this cross compiler works fine on ubuntu 14, and not I try in on ubuntu 18.
I tried to compile simple program
#include <stdio.h>
void main() {
printf("h\n");
}
gcc test.c -o test
When I compile it with gcc (to x86) all works fine, but when I compile it with cross compiler arm gcc I got error ...arm-buildroot-linux-uclibcgnueabu/4.*.*/cc1 : error while loading shared libraries: libmpfr.so.4 cannot open shared object file: No such file or directory
When I serach I can findlibmpfr.so.4 in the cross compiler path under /usr/lib
So even arm-gcc test.c -o test -L "<path_to_compiler>/usr/lib" got same error . and even export LD_LIBRARY_PATH=<path_to_compiler>/usr/lib didn't help
Related
I am trying to compile the mosquitto library with my custom c program. So WHat I have done is wrote a hello.c file, git cloned the latest mosquitto library from the below repository:
https://github.com/eclipse/mosquitto.git
and compiled it with the make command as below:
make
I had to remove the doc target as it was asking for some dependancy library. I don't have admin rights on this machine, hence don't want to be blocked by any dependancy lib. After the compilation what I have is the below:
src/mosquitto
./lib/libmosquitto.so.1
The I copied the libmosquitto.so.1 shared lib into a local folder called ~/hello/:
~/hello$ cp ~/mosquitto/lib/libmosquitto.so.1 .
then wrote a hello.c inside ~/hello/ which is as below:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
I can compile the hello.c and run it as below:
gcc -o hello hello.c
./hello
Hello World
But if I try to link the binary with the mosquitto library I get an error like the below:
gcc -o hello hello.c -lmosquitto
/usr/bin/ld: cannot find -lmosquitto
collect2: error: ld returned 1 exit status
The libmosquitto.so.1 lives in the same folder as the hello.c. I don't want to install the mosquitto library, rather would like to keep in a local folder and be able to link it. I have also tried the below with the hope that the -L. would point the linker to the present directory for the shared lib file but still get the same error:
gcc -o hello hello.c -L. -lmosquitto
/usr/bin/ld: cannot find -lmosquitto
collect2: error: ld returned 1 exit status
My ultimate objective is to cross compile the library for an arm target. So really need to understand how the linking of the shared library is failing so that I can use the same experience while cross compiling and link for the target. At the moment I am doing this on a x86 platform.
Can anyone please help?
/usr/bin/ld: cannot find -lmosquitto
The linker doesn't look for libmosquitto.so.1 -- it only looks for libmosquitto.a or libmosquitto.so.
Solution: ln -s libmosquitto.so.1 libmosquitto.so
./pub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
The problem here is that the runtime loader doesn't look in the current directory for libmosquitto.so.1 -- it only looks in system-configured directories.
You could fix this by adding export LD_LIBRARY_PATH=$HOME/mosquitto/lib, but this is suboptimal -- your binary will work or not depending on the environment.
A better solution is to change your link command like so:
gcc -o hello hello.c -L. -lmosquitto -Wl,-rpath=$HOME/mosquitto/lib
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 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
I have a Xilinx FPGA running a soft processor (PowerPC). I recently cross compiled Boost libraries for PowerPC and wanted to test it. So I used one of the sample programs and tried to cross compile it for my target. Below is the code
#include <boost/thread/thread.hpp>
void helloworld()
{
printf( "Hello World!");
}
int main()
{
boost::thread thrd(&helloworld);
thrd.join();
}
Below is my make file
CPP=ppc_4xx-g++
CFLAGS=-c -g -Wall
LDFLAGS_PowerPC=-L/shared/deps/powerpc/lib -L/opt/ELDK/4.2/ppc_4xx/lib/
LIBS_PowerPC=-lboost_thread -lboost_system -lpthread -lrt
INCLUDES=-I. -I./4.2.2/ -I./include -I/opt/ELDK/4.2/ppc_4xx/usr/include/
CPPFLAGS_PowerPC=-I/shared/deps/common/include
CPPFLAGS_COMMON=-I/shared/deps/powerpc/include
CPPFLAGS=$(CPPFLAGS_COMMON) $(CPPFLAGS_PowerPC)
all: helloworld
helloworld: helloworld.o
$(CPP) $(LDFLAGS_PowerPC) $(LIBS_PowerPC) helloworld.o -o helloworld
helloworld.o: helloworld.cpp
$(CPP) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) helloworld.cpp
clean:
rm -rf *.o helloWorld
I was able to generate the binaries but when I run the program on my target I get the below error
-/bin/sh: ./helloworld: not found
I checked online and found that the above problem comes when we have dynamic linking. My Boost libraries are present in the location /shared/deps/powerpc/lib and I have set the variable LD_LIBRARY_PATH accordingly using the below command.
export LD_LIBRARY_PATH=/shared/deps/powerpc/lib/:/opt/ELDK/4.2/ppc_4xx/lib/
But even then I get the same problem.
Below is the output of uname -ars
Linux (none) 3.0.0-14.1-build3+ #23 PREEMPT Thu Jan 3 18:44:27 CST 2013 ppc GNU/Linux
I don't have ldd installed on my target so I can't check the dynamic dependencies. But I am sure that, libraries are included. How can I proceed ?
Even though my embedded Linux system had a dynamic linker, it was not working. The problem was resolved when I used a dynamic linker provided with my tool chain and replaced it the correct directory. Now dynamic linking is fine.
I'm trying to get a "Hello World" application compiled for an ARM target. I'm cross compiling using gcc on Ubuntu/VMWare. If I compile for the host machine, it works fine. When I compile for the target, I get this error:
/root/picokernel/toolchain/arm-eabi/lib/libcs3hosted.a(hosted-sbrk.o): In function `_sbrk':
sbrk.c:(.text+0x74): undefined reference to `__cs3_heap_limit'
/root/picokernel/toolchain/arm-eabi/lib/libcs3hosted.a(hosted-sbrk.o):(.data+0x0): undefined reference to `__cs3_heap_start'
make: *** [HelloWorld] Error 1
So I think I need to link something in - perhaps my toolchain does not have the right libs? I was able to build the kernel, so I thought it was complete. Thanks! This is the target board. - runs Angstrom or Android.
makefile:
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
CROSS_LIB1=/root/picokernel/toolchain/arm-eabi/lib
CROSS_LIB2=/root/picokernel/toolchain/lib/gcc/arm-eabi/4.2.1
CFLAGS=-Wall
LDFLAGS= -L$(CROSS_LIB1) -L$(CROSS_LIB2) -lc -lcs3hosted -lg -lgcc --entry main
HelloWorld: HelloWorld.o
$(LD) HelloWorld.o $(LDFLAGS)
clean:
rm -f HelloWorld HelloWorld.o
program:
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello World\n");
return 0;
}
I gotta say, this is suspicious: -nostdlib
How about not using this flag?
The kernel does not use the C runtime library since the library does many—if not most—things not permitted by kernel code like file i/o and allocating memory.
Normally, you don't have to specify a library at all. gcc assumes the right thing. Try removing setting LDFLAGS altogether: I bet it works better.
Ok - finally worked this out, picked up a toolchain from the source here:
http://www.codesourcery.com/sgpp/lite/arm/portal/release1803
Hello World works great! Thanks for the suggestions
Does the toolchain you are using have a library called "lcs3arm" ? If so, try adding that to the list. You can also try "-lcs3" itself
Out of interest, which version of GCC are you using here? (i.e. which CodeSourcery release)