sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Userland Cross Compile Help (Newb Alert)

Sun Jan 12, 2014 2:44 am

I have been experimenting with raspimjpeg found here: https://github.com/silvanmelchior/userl ... s/raspicam, that is part of the userland code.

I have my cross compiler setup on an ubuntu VM for which I found instructions here:
http://airwiki.ws.dei.polimi.it/index.p ... aspberryPi

This works flawlessly for compiling my unedited raspimjpeg changes. However I am trying to utilize libgd2 (libgd2-noxpm-dev) in order to add time information to the image stream that is generated. I have included the gd header file:

Code: Select all

#include <gd.h>
However when I attempt to compile via my cross compiler I get a "fatal error: gd.h not a file or directory".
My directory structure looks something like this:

Code: Select all

~/Sources
    /raspberrypi
        /userland
        /rootfs (copied from pi via rsync)
            /usr (gd.h exists in /usr/include/gd.h)
            /lib
        Toolchain-RaspberryPi.cmake
I am attempting to use the buildme file in the userland code, I have modified it to use the CMAKE_TOOLCHAIN_FILE from the tutorial listed above. See Below: Toolchain-RaspberryPi.cmake

Code: Select all

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER $ENV{HOME}/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/Sources/raspberrypi/rootfs)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Relevant portion of userland/buildme file:

Code: Select all

        # Cross compile on a more capable machine
        mkdir -p build/arm-linux/release/
        pushd build/arm-linux/release/
        cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/Sources/raspberrypi/Toolchain-RaspberryPi.cmake -DCMAKE_BUILD_TYPE=Release ../../..
        make -j 6

        if [ "$1" != "" ]; then
         sudo make install DESTDIR=$1
        fi

I have exhausted myself trying to find information on how to fix this issue online, unfortunately I don't quite know the right questions to ask, being a novice when it comes to complex compilation of C.

Any assistance provided would be greatly appreciated!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24130
Joined: Sat Jul 30, 2011 7:41 pm

Re: Userland Cross Compile Help (Newb Alert)

Sun Jan 12, 2014 10:14 am

I presume you have installed the dev version of the library you are trying to use? You'll need the source code for it, and probably have to build it with the cross compiler too.

But you particular problem is that either a) the library isn't installed so the header file doesn't exist or b) Your include paths in the make file do not include the folder where the header file is.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: Userland Cross Compile Help (Newb Alert)

Sun Jan 12, 2014 5:43 pm

jamesh wrote:I presume you have installed the dev version of the library you are trying to use? You'll need the source code for it, and probably have to build it with the cross compiler too.

But you particular problem is that either a) the library isn't installed so the header file doesn't exist or b) Your include paths in the make file do not include the folder where the header file is.
Jamesh, thanks so much for the response. I'm guessing the problem is option b, however I cannot seem to figure out how to let CMAKE know where the proper path is. The gd.h file lives on the host system I am trying to cross compile from and was copied into a rootfs folder from the pi. The challenge I am having is that I simply cannot get cmake/compiler to recognize the rootfs folders /usr and /lib folders respectively. Unfortunately I just don't have enough experience with cmake and compiling complex c applications to troubleshoot this one.

Any pointers on how I might be able to correlate the rootfs folder to the build process?

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: Userland Cross Compile Help (Newb Alert)

Sun Jan 12, 2014 8:32 pm

I have some progress to report. I was able to get the issue of the gd.h fatal error resolved by adding the following to my Toolchain-RaspberryPi.cmake file.

Code: Select all

SET(CMAKE_C_FLAGS "-L$ENV{HOME}/Sources/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf -I$ENV{HOME}/Sources/raspberrypi/rootfs/usr/include")
SET(CMAKE_CXX_FLAGS "-L$ENV{HOME}/Sources/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf -I$ENV{HOME}/Sources/raspberrypi/rootfs/usr/include")
So, now I am getting a new error that I don't quite understand.. perhaps I need to create some sym links? Anyway, here is the latest error:

Code: Select all

/home/john/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lgd
collect2: error: ld returned 1 exit status
I believe I am getting this error due to a modification I made to the CMakeLists.txt in the raspicam application:

Code: Select all

target_link_libraries(raspimjpeg mmal_core mmal_util mmal_vc_client vcos bcm_host gd)
The libgd.a file is in my ~/Sources/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf directory.

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: Userland Cross Compile Help (Newb Alert)

Mon Jan 13, 2014 6:55 am

OK. So, I continue on my quest to get libgd compiled with raspimpjeg. Here is where I am at:

I added the following to the CMakeLists.txt file located in the raspicam app directory:

Code: Select all

link_directories($ENV{HOME}/Sources/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf)
This resolved the issue:

Code: Select all

/home/john/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lgd
collect2: error: ld returned 1 exit status
Unfortunately, now I receive the following issue regarding pthread

Code: Select all

/home/john/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.so.0
/home/john/Sources/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
make[2]: *** [../../bin/raspivid] Error 1
make[1]: *** [host_applications/linux/apps/raspicam/CMakeFiles/raspivid.dir/all] Error 2
What is interesting about this is that it is located in the rootfs folder as well as the toolchain folders. I have read via several issues on stack exchange to alter the libpthread.so located here: /arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/lib/arm-linux-gnueabihf/libpthread.so, to remove the absolute paths from:

Code: Select all

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/arm-linux-gnueabihf/libpthread.so.0 /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a )
To:

Code: Select all

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libpthread.so.0 libpthread_nonshared.a )
Unfortunately this did not work either, I still get the same error! Anyone see something I am doing wrong here?!

Return to “C/C++”