Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JMona1
New Contributor I
2,013 Views

Moving a program from Eclipse to compile with GCC on the Edison

Jump to solution

I have the following demo program which compiles and runs within Eclipse on the Edison "Embedded Evaluation Board"

# include "mraa.h"

# include

# include

int main()

{

mraa_gpio_context d_pin = NULL;

d_pin = mraa_gpio_init(13);

mraa_gpio_dir(d_pin, MRAA_GPIO_OUT);

while(1)

{

mraa_gpio_write(d_pin, 0);

sleep(1);

mraa_gpio_write(d_pin, 1);

sleep(1);

}

return MRAA_SUCCESS;

}

The program is called test1.c

Because I want to run a program on power on as a service without logon, I was told I must compile the program on the Edison with GCC. From the Command line on the Edison I typed:-

gcc test1.c –o test1

I got back:-

/usr/lib/gcc/i586-poky-linux/4.9.1/../../../crt1.o: In function `_start':

/export/users/neck/iotdk_3.5_dev/workdir/build_edison/tmp/work/core2-32-poky-linux/glibc/2.20-r0/git/csu/../sysdeps/i386/start.S:111: undefined reference to `main'

collect2: error: ld returned 1 exit status

Anybody got some pointers as to how one compiles Eclipse IoT c code with GCC from the Edison command line

Thanks in advance

John

1 Solution
Bernard_G_Intel
Employee
60 Views

But to go a little bit further:

Because I want to run a program on power on as a service without logon, I was told I must compile the program on the Edison with GCC

I am not sure this is true.

You can use anyway Eclipse to compile your project. Once compiled you will find the binary in the Debug folder of your folder project in your workspace (so something like (.../worksace_iot//Debug)

You can copy this binary to your Edison board then.

And secondly, your error is strange as I don't have the same on my board (on my side it is complaining about missing mraa library).

Is your Edison image up to date?

Which version off gcc do you have? (gcc --version returns 4.9.1 on my side)

View solution in original post

5 Replies
Bernard_G_Intel
Employee
60 Views

The easiest way to do what you want to do is to use first Eclipse to compile your project and look at the output view to see what Eclipse is really doing to compile your file.

In your case, I deduced that here is what you should do (I guess some parameters could be removed):

gcc -I/usr/include/mraa -O0 -g3 -Wall -c -fmessage-length=0 --sysroot= -m32 -march=i586 -c -ffunction-sections -fdata-sections -o test1.o test1.c

gcc --sysroot= -o test1 test1.o -lmraa

Bernard_G_Intel
Employee
61 Views

But to go a little bit further:

Because I want to run a program on power on as a service without logon, I was told I must compile the program on the Edison with GCC

I am not sure this is true.

You can use anyway Eclipse to compile your project. Once compiled you will find the binary in the Debug folder of your folder project in your workspace (so something like (.../worksace_iot//Debug)

You can copy this binary to your Edison board then.

And secondly, your error is strange as I don't have the same on my board (on my side it is complaining about missing mraa library).

Is your Edison image up to date?

Which version off gcc do you have? (gcc --version returns 4.9.1 on my side)

View solution in original post

JMona1
New Contributor I
60 Views

Sideralis, the first part of your reply got me really excited. I would really like to develop everything in Eclipse and then just copy across the executable to the Edison (without doing everything with GCC on the Edison itself).

So for others that may need this I did the following.....

I started with the test file test2.c:-

# include "mraa.h"

# include

# include

int main()

{

int i;

mraa_gpio_context d_pin = NULL;

d_pin = mraa_gpio_init(13);

mraa_gpio_dir(d_pin, MRAA_GPIO_OUT);

// printf("Start of test1\n");

for(i=0; i < 5; i++)

{

// printf("i=%d\n",i);

mraa_gpio_write(d_pin, 0);

sleep(1);

mraa_gpio_write(d_pin, 1);

sleep(1);

}

// printf("End of test1\n");

return MRAA_SUCCESS;

}

This program runs the file when run within Elipse itself on the Intel Development board. The onboard LED flashes 4 times.

Within Eclipse I found the test1.c executable file in the directory workspace_iot\test2\Debug on my windows PC. It's just named "test2" and has a file size of 64K.

With a program called WinSCP I copied it across to the Edison directory /home/root. The properties of this file are (rw-r—r--, 644). Had to change it to (rwxr—r--, 744)

If I then type ./test2 from the /home/root directory the program works, (4 flashes of the LED) !!!

THANK YOU SO MUCH. You saved me a lot of hassle/time. Others on previous postings did not know this!!!!

<span style="color: # 000000; font-family: Times New Roman; font-size: 12pt;"...

NNath3
New Contributor II
60 Views

monahanz wrote:

THANK YOU SO MUCH. You saved me a lot of hassle/time. Others on previous postings did not know this!!!!

Actually, others on previous postings didn't see this as your biggest problem, and weren't sure where to begin to explain to you that Eclipse is not even a compiler .

One thing bothers me, if I remove the comments "//" in the above source code, I don't see the printf text. Any ideas?

I suggested an explanation for this to you "on previous postings". Riddle me this: if a program is being run without a user logged in (e.g., as a service, during boot), then to which user's console should the OS display anything directed at stdout?

JMona1
New Contributor I
60 Views

Well if that's the case they did no mention it:- "and weren't sure where to begin to explain to you that Eclipse is not even a compiler ", That's the problem with this Intel Edison forum. Its written by people that already know most of the stuff. If you look over the postings of beginners the help is thin - at best. Most of the time the 'experts' just slap off pointers to pointers to pointers to earlier treads. This is of little help to a beginner.

Use my case as an example. I want to run a simple C type program on and Edison (written in the Eclipse IDE) and have it run each time on power up. A simple request I think.

The answer should be along the lines I ended up writing as a solution here. Too much trouble/time you might say, OK then don't cast yourself as a forum trying to be helpful to Edison users that may develop IoT applications for the hardware. Don't expect to get high ratings on an Intel survey.

Take a look at the Raspberry forums. Very informative and helpful. The reason that unit has done so well world wide is that they early on focused in helping new users get going. You don't have to be a Linux guru to develop applications practical applications.

I am strictly a hobbiest and am developing an Edison board for an antique computer system. There are about 100 people directly involved. My task has been to pry out of the experts here enough information that an Edison unit can be setup and used as described here http://s100computers.com/My%20System%20Pages/Edison%20Board/Edison%20CPU%20Board.htm http://s100computers.com/My%20System%20Pages/Edison%20Board/Edison%20CPU%20Board.htm.

As to your second question: "Riddle me this: if a program is being run without a user logged in (e.g., as a service, during boot), then to which user's console should the OS display anything directed at stdout?"

I would think the output would go to the same console output the other "gobbely guuk" output goes while the system is booting up. Heck even the .service scripts send output. Even my test2.service sent a string Test2 Program Activated <------</span> What's the problem?

John

Reply