Closed jaskiratsingh2000 closed 3 years ago
These are the following steps I followed for cross-compilation of the small Cpp program which I made in cross-compile-test repository
Step 1: I logged into my Raspberry Pi board by writing the following command into my Ubuntu terminal
ssh pi@[IP_address_of_your_Pi_here]
It will then ask for the Raspberry Pi password.
Step 2: Then I download the ARM toolchain for Raspberry Pi in the Ubuntu terminal
wget https://github.com/raspberrypi/tools/archive/master.zip
Step 3: Now within the Ubuntu terminal, I moved inside the toolchain directory by following this command
cd master/tools-master/arm-bcm2708
Make sure the master.zip is unzipped before running step 3.
Step 4: Do the "ls" to see all the toolchains
ls
Step 5: Now if your OS is 32/64 bit then run the following command For 32 bit:
cd gcc-linaro-arm-linux-gnueabihf-raspbian/bin/
For 64 bit:
cd gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
NOTE: mine is 64 Bit
Step 6: Now see the arm toolchain by doing "ls"
ls
Step 7: Then I added the arm toolchain path to the system environment variable, so first write the following thing to get the path
pwd
That path will come out to be like this - /home/user/master/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
Step 8: Go back to the home directory by writing the following command
cd ~
Step 9: Using the following command to update the path variable
export PATH=$PATH:/home/user/master/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
Step 10: Printing the value of the path variable to check if the path was set correctly
echo $PATH
After running this command we will get this following thing which denotes that our toolchain path has been updated correctly
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/user/master/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
Step 11: You can create or include any C/C++ file. I already made the C++ program which has been kept in the cross-compile-test repo with the name hello-world.cpp
Step 12: Now compile this code with the g++ compiler
g++ -o hello /home/user/Desktop/cross-compile-test/hello-world.cpp
Checking the output - ./hello
Step 13: Now you can use the file command to know the binary file
file hello
Output:
hello: ELF 64-bit LSB shared object, **x86-64**, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=971c6d5271dbcd9a225a4ce3d3de99bdb99cbfe9, for GNU/Linux 3.2.0, not stripped
Here we see that it is compiled for the x86-64 system
Step 14: Now we will compile with the arm toolchain
arm-linux-gnueabihf-g++ hello-world.cpp -o hellom
Step 15: Now you can use the file command t know the property of this file
file hellom
Output:
hellom: ELF 32-bit LSB executable, **ARM**, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.26, BuildID[sha1]=528f3904ef4e619e06d26bce3c1e42283f0c9c78, not stripped
Here we see that this binary file has been converted for the ARM architecture and if you run this file on this pc then you will get an error
Step 16: Now let's copy this file on the raspberry pi by following this command on the home location
scp hellom pi@192.168.1.75:~
Step 17: Now you can switch to the Raspberry Pi console and type the following command to see if that file has been copied to the home directory or not.
ls
After running this I see that it has been successfully copied to my Raspberry Pi file.
Step 17: Now you can change the permission of this "hellom" by following this command
sudo chmod 777 hellom
Step 18: Run this file by following this command
./hellom
and I successfully get the following output
Helo World! Welcome to Cross-Compilation Test. :)
Hurrrraaaay!!!!!!!! 💯 :)
This is the CMakeLists.txt file
cmake_minimum_required (VERSION 3.10)
#Setting the variables
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
#Defining the project
project(yolov5)
#Adding the executable files
add_executable(
yolov5
models/common.py
modelsexperimental.py
models/export.py
models/yolo.py
utils/activations.py
utils/autoanchor.py
utils/datasets.py
utils/general.py
utils/google_utils.py
utils/loss.py
utils/metrics.py
utils/plots.py
utils/torch_utils.py
)
Error
user@user-Satellite-Pro-B40-A:~/Desktop/YOLO/bin$ cmake -DCMAKE_TOOLCHAIN_FILE=/home/user/master/Toolchain-RaspberryPi.cmake ../yolov5
-- The CXX compiler identification is GNU 4.8.3
-- Check for working CXX compiler: /home/user/master/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/user/master/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:7 (add_executable):
Cannot find source file:
modelsexperimental.py
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error at CMakeLists.txt:7 (add_executable):
No SOURCES given to target: yolov5
CMake Generate step failed. Build files cannot be regenerated correctly.
user@user-Satellite-Pro-B40-A:~/Desktop/YOLO/bin$ cmake -DCMAKE_TOOLCHAIN_FILE=/home/user/master/Toolchain-RaspberryPi.cmake ../yolov5
-- Configuring done
CMake Error: Cannot determine link language for target "yolov5".
CMake Error: CMake can not determine linker language for target: yolov5
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
user@user-Satellite-Pro-B40-A:~/Desktop/YOLO/bin$ make
Scanning dependencies of target yolov5
[100%] Linking CXX executable yolov5
arm-linux-gnueabihf-g++: fatal error: no input files
compilation terminated.
make[2]: *** [CMakeFiles/yolov5.dir/build.make:69: yolov5] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/yolov5.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I was able to to install this without the cross-compilation
This issue surfs around the steps and the ways I used to cross-compile the very basic cpp program first and then the ultralytics/yolov5 repository.