[ECOS] Simple compile

Sergei Gavrikov sergei.gavrikov@gmail.com
Wed Apr 8 08:57:00 GMT 2009


On Wed, Apr 08, 2009 at 12:21:27AM -0700, grahamlab wrote:
> 
> Hello everyone
> I am new to ecos and am trying to compile a simple program that uses the
> sleep function
> My code include <unistd.h> but when I compile i get this error
> 
> hello.cpp:34: error: ‘sleep’ was not declared in this scope
> 
> I am compiling using the following command
> 
> arm-eabi-g++ -c -I ../DevBoardFast_install/include/ -I
> /opt/ecos/ecos-3.0/packages/isoinfra/v3_0/include/  -Wall -Wpointer-arith
> -Wstrict-prototypes -Wundef -Woverloaded-virtual -Wno-write-strings
> -mcpu=cortex-m3 -mthumb -g -O2 -ffunction-sections -fdata-sections -fno-rtti
> -fno-exceptions  hello.cpp
> 
> The code looks like this
> 
> #include <unistd.h>
> #include <stdio.h>
> 
> int main(int argc, char** argv)
> {
>     sleep(10);
>     printf("Hello main\n");
> }
> 
> Please tell me why this does not compile
> 
> Thanks
> 
> Graham

Graham,

To have sleep() you have to add posix package to default template. Do
you really need in the bloat posix stuff? The eCos has own "sleep" --
cyg_thread_delay(). Please, start to read eCos documentation. So, a
solution is

ecosconfig add posix

IMHO, you have to prepare a good Makefile to play with eCos. Why do you
use C++ ?!. There are good examples under eCos `examples' directory. Try
the examples, first. Those build_Makefile, build_Make.params are nice
script-helpers to get a test farm. build_Make.params is most important
then. It rebuilds actual GCC flags for project. Every time when you
rebuild eCos, run build_Make.params (U.T.S.L.) in a project directory.

Just a demo about that eCos can do all for you

i. build eCos

ecosconfig new stm3210e
ecosconfig add posix
ecosconfig tree
make -s

ii. Stand up a test farm

mkdir test
cd test
cp $ECOS_REPOSITORY/../examples/build_Make.params .
DST=test SRCS=test.c $ECOS_REPOSITORY/../examples/build_Makefile ..
echo -ne 'clean:\n\trm -f test.o test\n' >> Makefile

cat >test.c<<EOF
#include <stdio.h>
#include <unistd.h>

int
main(void)
{
    sleep(10);
    printf("Test done\n");
    return 0;
}
EOF

make -s

I've got

ls
Makefile  Make.params  test  test.c  test.o

And there is sleep there

arm-eabi-nm test | grep sleep
68009d98 T _ZN10Cyg_Thread5sleepEv
6800c2a4 T nanosleep
6800c358 T sleep

But, eCos source can look as (no need posix package to compile it)

#include <stdio.h>
#include <cyg/kernel/kapi.h>

int
main(void)
{
    while (true) {
	cyg_thread_delay(100);
	printf("I'm still alive\n");
    }
    return 0;
}


This week read these manuals:
http://ecos.sourceware.org/docs.html


Sergei

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list