add libdl and extension examples

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1080 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc 2010-11-21 23:12:42 +00:00
parent 03951e4e38
commit 5f838f86aa
5 changed files with 140 additions and 2 deletions

View File

@ -32,5 +32,7 @@ Export('rtconfig')
Export('projects') Export('projects')
Export('TARGET') Export('TARGET')
SConscript(RTT_ROOT + '/components/module/tetris/SConscript', variant_dir='build/tetris', duplicate=0) SConscript(RTT_ROOT + '/components/module/tetris/SConscript', duplicate=0)
SConscript(RTT_ROOT + '/components/module/basicapp/SConscript', variant_dir='build/basicapp', duplicate=0) SConscript(RTT_ROOT + '/components/module/basicapp/SConscript', duplicate=0)
SConscript(RTT_ROOT + '/components/module/extension/SConscript', duplicate=0)
SConscript(RTT_ROOT + '/components/module/extapp/SConscript', duplicate=0)

View File

@ -0,0 +1,34 @@
Import('env')
Import('projects')
Import('RTT_ROOT')
Import('rtconfig')
Import('TARGET')
RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe '
# group definitions
group = {}
group['name'] = 'examples'
group['src'] = Glob('*.c')
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/include', RTT_ROOT + '/components/module', RTT_ROOT + '/components/libdl']
group['CPPDEFINES'] = ''
target = 'extapp.so'
POST_ACTION = RTMLINKER + '-l ' + TARGET + ' -o extapp.mo ' + '$TARGET'
# add group to project list
projects.append(group)
src_local = Glob('extapp.c')
env.Append(CCFLAGS = group['CCFLAGS'])
env.Append(CPPPATH = group['CPPPATH'])
env.Append(CPPDEFINES = group['CPPDEFINES'])
module_env = env.Clone(CPPDEFINE = 'RT_MODULE')
module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC')
module_env.Replace(LINK = 'arm-none-eabi-ld')
module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e rt_application_entry -nostdlib -s')
module_env.Program(target, src_local)
module_env.AddPostAction(target, POST_ACTION)

View File

@ -0,0 +1,35 @@
#include <rtthread.h>
#include <dlfcn.h>
typedef void (*func)(void);
int rt_application_entry(void)
{
func f1, f2, f3, f4, f5;
void* handle = dlopen("/mo/ext.so", RTLD_NOW);
if(handle != RT_NULL)
{
f1= (func)dlsym(handle, "function1");
f2= (func)dlsym(handle, "function2");
f3= (func)dlsym(handle, "function3");
f4= (func)dlsym(handle, "function4");
f5= (func)dlsym(handle, "function5");
if(f1 != RT_NULL) f1();
else rt_kprintf("dlsym function1 failed.\n");
if(f2 != RT_NULL) f2();
else rt_kprintf("dlsym function2 failed.\n");
if(f3 != RT_NULL) f3();
else rt_kprintf("dlsym function3 failed.\n");
if(f4 != RT_NULL) f4();
else rt_kprintf("dlsym function4 failed.\n");
if(f5 != RT_NULL) f5();
else rt_kprintf("dlsym function5 failed.\n");
}
dlclose(handle);
return 0;
}

View File

@ -0,0 +1,34 @@
Import('env')
Import('projects')
Import('RTT_ROOT')
Import('rtconfig')
Import('TARGET')
RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe '
# group definitions
group = {}
group['name'] = 'examples'
group['src'] = Glob('*.c')
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/include', RTT_ROOT + '/components/module']
group['CPPDEFINES'] = ''
target = 'extension.so'
POST_ACTION = RTMLINKER + '-l ' + TARGET + ' -o extension.mo ' + '$TARGET'
# add group to project list
projects.append(group)
src_local = Glob('extension.c')
env.Append(CCFLAGS = group['CCFLAGS'])
env.Append(CPPPATH = group['CPPPATH'])
env.Append(CPPDEFINES = group['CPPDEFINES'])
module_env = env.Clone(CPPDEFINE = 'RT_MODULE')
module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC')
module_env.Replace(LINK = 'arm-none-eabi-ld')
module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -e 0 -shared -fPIC -nostdlib -s')
module_env.Program(target, src_local)
module_env.AddPostAction(target, POST_ACTION)

View File

@ -0,0 +1,33 @@
#include <rtthread.h>
#include <rtm.h>
void function1(void)
{
rt_kprintf("Hello RT-Thread function1\n");
}
void function2(void)
{
rt_kprintf("Hello RT-Thread function2\n");
}
void function3(void)
{
rt_kprintf("Hello RT-Thread function3\n");
}
void function4(void)
{
rt_kprintf("Hello RT-Thread function4\n");
}
void function5(void)
{
rt_kprintf("Hello RT-Thread function5\n");
}
RTM_EXPORT(function1)
RTM_EXPORT(function2)
RTM_EXPORT(function3)
RTM_EXPORT(function4)
RTM_EXPORT(function5)