Closed oosavu closed 3 years ago
@oosavu Just add link_directories(${rootfs_dir}/usr/lib/arm-linux-gnueabihf)
at end of your CMakeList.txt
as follows:
cmake_minimum_required(VERSION 3.10)
project(rpi_main)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
add_executable(rpi_main main.cpp ${rpi_src})
include_directories(${rootfs_dir}/usr/include/arm-linux-gnueabihf)
link_directories(${rootfs_dir}/usr/lib/arm-linux-gnueabihf)
and problem will be solved.
Warning ⚠️ : Also make sure you ran rsync
command with sudo
privileges and fixed symbolic links, as mentioned in docs at step-6 and step-7
@oosavu Test solution in previous comment, and then comment your results here.
Thanks for quick reply!
link_directories(${rootfs_dir}/usr/lib/arm-linux-gnueabihf)
does not help. I have the same errors.SET(CMAKE_SYSROOT ${rootfs_dir})
!Similar bug has already present: https://github.com/abhiTronix/raspberry-pi-cross-compilers/issues/3 But unfortunately solutions from this old bug does not help for me :( (unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES))
So for now commenting this line in the toolchain file is only that i can do. It is not good because it brokes many benefits of cmake, like "find_library".
If you have another ideas what can i do - it will be great!
p.s.: you can merge four rsync commands into one: rsync -vR --progress -rl --delete-after --safe-links pi@192.168.0.100:/{lib,usr,opt/vc/lib} $HOME/cv/rootfs
p.s.2: it will be great to add this hello world application to you repository since it is hard to find good example for cross-compilation project!
Similar bug has already present: #3 But unfortunately solutions from this old bug does not help for me :( (unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES))
@oosavu Apologies but I'm unable to understand if you still having bugs after SET(CMAKE_SYSROOT ${rootfs_dir})
fix or you already resolved them? If there are bugs, are they similar to #3?
So for now commenting this line in the toolchain file is only that i can do. It is not good because it brokes many benefits of cmake, like "find_library".
If you have another ideas what can i do - it will be great!
Also, by "this line" you meant "unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES)" ?
p.s.2: it will be great to add this hello world application to you repository since it is hard to find good example for cross-compilation project!
Sure, I'm going paste the results of hello world application in our wiki docs.
@abhiTronix
uuups. My mistake. #3 is NOT a similar bug. Forget about it.
"this line" - is "SET(CMAKE_SYSROOT ${rootfs_dir})".
This works:
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR armhf)
set(tools /home/oosavu/cv/cross-pi-gcc-8.3.0-0)
set(rootfs_dir /home/oosavu/cv/rootfs)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_FIND_ROOT_PATH ${rootfs_dir})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)
@oosavu Nice. I'll close this once wiki docs are updated. Thank you.
Omitting setting CMAKE_SYSROOT is not a solution. It is rather a workaround and does not work for projects where sysroot must be defined.
I think this issue is related with the toolchain. However, I don't know how it works for @abhiTronix given that I followed his guide.
@fuzun Stop Hijacking other issues, and open your own or rather just quit with your bullshit. First of all, This is not the problem with Toolchains but with CMake (if you being ignorant), since CMake prefixes all paths with the CMAKE_SYSROOT
value if defined, so find_library
(used to find required libs for compilingmain.cpp
) will be looking in the wrong places. You can easily test this by copying your entire $WORKSPACE
to $CMAKE_SYSROOT/$WORKSPACE
. Then, the CMake scripts worked fine, and find_library
is found correctly and it compiles without any problems. Therefore as @oosavu correctly concluded, only CMAKE_FIND_ROOT_PATH
is the correct way to handle the sysroot.
@fuzun Bring a right attitude on the table to comment here or just begone.
Hello!!! My enviroment is:
toolchain_s.cmake:
CMakeList.txt:
main.cpp:
Error occurs on the linkage step: ld: cannot find crt1.o: No such file or directory ld: cannot find crti.o: No such file or directory ld: cannot find -lm
What i'm doing wrong?! i spent many time for migrating to this tool and it is a last obstacle. anybody please help! Do anybody show me their toolchain file?
output of make and cmake: