6 Replies Latest reply on Sep 30, 2015 5:38 AM by prashast.srivastava

    Cross compiler toolchain clarification

    prashast.srivastava

      So I was trying to build a cross compiler toolchain on my laptop running ubuntu 14.04 and using the instructions listed in http://downloadmirror.intel.com/23962/eng/Quark_BSP_BuildandSWUserGuide_329687_007.pdf I was able to successfully create one after following instructions as listed in Section 7. After that I was trying to cross compile a sample program on the laptop to ensure that my toolchain was working fine. The sample program which I'm trying to cross compile is a simple hello world program stated below.

       

      #include <stdio.h>

      main()

      {

      printf("Hello, world!\n");

      }

       

      Now the steps which I follow in order to cross compile it for a quark processor are these. Correct me if I am wrong.

       

      1)  source /opt/iot-devkit/1.6.1/environment-setup-i586-poky-linux

      2)  {CC} hellocross.c -o hellocross1

       

      When I try doing this the error I get is the following:-

       

      Fatal Python error: Py_Initialize: Unable to get the locale encoding

      ImportError: No module named 'encodings'

      Aborted (core dumped)

       

      However, if I end up changing the second command like this:-

      ${CC} hellocross.c -o hellocross1

       

      I am able to successfully compile the program. And when I try to execute this executable on the laptop I am able to do so. Shouldn't running the executable on the laptop raise me a error because I am compiling it for a quark processor? Am I wrong in assuming that? I just want to make sure which is the right step to follow before I try SSH-ing to my board and running the file there.

       

      And kindly let me know if when I use gdb on this cross compiled executable, the hex addresses which are shown when I do something simple like for eg. "print main". Would these addresses assigned remain the same when I run the same executable on the board?

        • 1. Re: Cross compiler toolchain clarification
          CMata_Intel

          Hi prashast.srivastava,

           

          I will test this, and I will run the executable also in the board to see if it runs in there too.

          I think this is because the host machine you are using has a compatible GCC version, also you are compiling a generic code so there shouldn't be problems between the environments. If you use other resources from the board to compile a more specific code you should have problems if you run the executable in the host machine. I will run some tests and I will let you know my results. If you have ran some tests let us know.

           

          Kind regards,

          Charlie

          • 2. Re: Cross compiler toolchain clarification
            mhahn

             

             

            However, if I end up changing the second command like this:-

            ${CC} hellocross.c -o hellocross1

             

            '{CC}' doesn't make sense to me '${CC}' looks reasonable

             

             

            I am able to successfully compile the program. And when I try to execute this executable on the laptop I am able to do so. Shouldn't running the executable on the laptop raise me a error because I am compiling it for a quark processor? Am I wrong in assuming that? I just want to make sure which is the right step to follow before I try SSH-ing to my board and running the file there.

             

            It's not so much the Quark processor - which is x86 as well - but more the Linux running on Galileo which most likely differs to what you have on your laptop. Nevertheless, if the laptop is running Linux the application may still run. Depends on various factors (e.g. what and how you linked). If you run the eglibc based image on Galileo it's more likely to run than if you use the uclibc based one.

             

             

            And kindly let me know if when I use gdb on this cross compiled executable, the hex addresses which are shown when I do something simple like for eg. "print main". Would these addresses assigned remain the same when I run the same executable on the board?

             

            IMHO yes. If you run the eglibc based image you may want to try the Eclipse IDE within the Intel IoT devkit which provides remote debugging to your Galileo target within the IDE. That IDE also has the cross compiler already included. Thus you don't have to care about console based cross compilation but just compile to Galileo target. Eclipse will upload the binary for you and execute remotely

            • 3. Re: Cross compiler toolchain clarification
              prashast.srivastava

              Ok so as of now I have been able to ssh to my board and have successfully identified that my cross compiler toolchain is working fine mainly because I was able to cross compile a hello world C program, send it to the board through scp and then was able to execute it over there. I am running the eglibc based image as suggested by you.

               

              Now the next thing that I would desire to do with this cross compiler toolchain is that I wanted to use these flags "-fno-stack-protector, -static, -m32" while cross compiling my C program.I tried putting these flags as follows:

               

              ${CC} -fno-stack-protector -static -m32 testprog.c -o testprog

               

              However, when I did this. I got the following error:

              /opt/iot-devkit/1.6.1/sysroots/x86_64-pokysdk-linux/usr/libexec/i586-poky-linux/gcc/i586-poky-linux/4.8.2/ld: cannot find -lc

              collect2: error: ld returned 1 exit status



              I even tried putting these flags at different positions while cross compiling but to no avail. I even tried trying to use those flags by ssh-ing into the board and then trying to compile over there with these flags but the same error was raised. The C program in itself does compile and execute correctly when I compile it on my laptop(using gcc) with these flags. However when I try to cross compile with flags, this problem arises.


              Let me know is it possible for me to use these flags while cross compiling a program? Are there any libraries missing which I might need to get before I can use these flags while cross compiling? Is there any other way in which I can use these flags while cross compiling?

              • 4. Re: Cross compiler toolchain clarification
                CMata_Intel

                Hi prashast.srivastava,

                 

                The problems seems to be related with -static, let's try with the following line and let us know the outcome

                ${CC} -fno-stack-protector -static-libgcc -m32 testprog.c -o testprog

                 

                Kind regards,

                Charlie

                • 5. Re: Cross compiler toolchain clarification
                  prashast.srivastava

                  Adding -libgcc after static worked like a charm. Was able to cross compile and execute successfully on the galileo board. Thanks a lot for the help Charlie!

                  • 6. Re: Cross compiler toolchain clarification
                    prashast.srivastava

                    Am using the eglibc based image and yes you were right the addresses assigned remained the same regardless of whether I ran it on my laptop or on the board.