c++ in RT-Linux

"Vasin Pichitsurakij" <[email protected]> Fri, 10 Mar 2006 01:08:39 +0900 (JST)
Newsgroups gmane.linux.real-time.rtlinux.general
Message-ID <33523.60.44.210.122.1141920519.squirrel@www.webmail.thaiexcite.com>
 Please help me how to use C++ in RT-Linux. I have tried many way for use
C++ but it is still not work.

  I try to run a hello.c (C language)that is an example program coming wi=
th
rtlinux and everything work fine but I really want to use C++ instead of =
C.

 I try to run a hello.cpp that is an example program for C++ that come wi=
th
rtlinux. I can compile hello.cpp. after that I do this message.

> [root@ss-sw1 cpp]# insmod rtl_cpp.o
> [root@ss-sw1 cpp]# insmod app.o
> app.o: unresolved symbol __cxa_pure_virtual
> app.o: unresolved symbol __cxa_atexit
> app.o:
> Hint: You are trying to load a module without a GPL compatible license
>       and it has unresolved symbols.  Contact the module supplier for
>       assistance, only they can help you.
>
> [root@ss-sw1 cpp]# insmod hello.o
> hello.o: unresolved symbol __cxa_pure_virtual
> hello.o: unresolved symbol __do_global_ctors_aux
> hello.o: unresolved symbol __cxa_atexit
> hello.o: unresolved symbol __dso_handle
> hello.o: unresolved symbol __do_global_dtors_aux
> hello.o:
> Hint: You are trying to load a module without a GPL compatible license
>       and it has unresolved symbols.  Contact the module supplier for
>       assistance, only they can help you.

After that someone suggest me something then I do this

In my /usr/src/rtlinux/rtlinux-3.1/rtl.mk.I change CXXFLAGS by adding
-fno-rtti -fno-use-cxa-atexit
//------------------begin rtl.mk-------------------
CXXFLAGS =3D -D__KERNEL__ -Wall -Wstrict-prototypes -fno-strict-aliasing
-pipe -march=3Di686 -DMODULE -DMODVERSIONS -include
/usr/src/rtlinux/linux/include/linux/modversions.h -g -D__RTL__
-D_LOOSE_KERNEL_NAMES -I/usr/src/rtlinux/rtlinux-3.1/linux/include
-I/usr/src/rtlinux/rtlinux-3.1/include
-I/usr/src/rtlinux/rtlinux-3.1/include/compat
-I/usr/src/rtlinux/rtlinux-3.1/include/posix -fno-exceptions -fno-rtti
-fno-use-cxa-atexit
//------------------end rtl.mk -------------------------

adding this to rtl_cpp.c
void __cxa_pure_virtual (void)
{
        Rtl_printf(=93__cxa_pure_virtual called\n=94);
}

//------------------- begin hello.c --------------------
#include <rtl_cpp.h>

pthread_t thread;

class A {
protected:
int a;
public:
virtual void print()=3D0;
A() { a =3D 1; rtl_printf("initializing A\n");}
virtual ~A() { rtl_printf("uninitializing A\n"); }
};

class B : public A
{
public:
B() { a =3D 1; rtl_printf("initializing B\n");}
~B() { rtl_printf("uninitializing B\n");}
virtual void print() { rtl_printf("B::print: %d\n", a); }
};

void * start_routine(void *arg)
{
struct sched_param p;
p . sched_priority =3D 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);

pthread_make_periodic_np (pthread_self(), gethrtime(), 500000000);

while (1) {
pthread_wait_np ();
rtl_printf("I'm here; my arg is %x\n", (unsigned) arg);
}
return 0;
}

B a;
A *ptr_b;

int init_module(void) {
__do_global_ctors_aux();
ptr_b =3D new B;
ptr_b -> print();
return pthread_create (&thread, NULL, start_routine, 0);
}

void cleanup_module(void) {
pthread_delete_np (thread);
delete ptr_b;
__do_global_dtors_aux();
}
//------------------------- end hello.c -------------------

After that I do this.

[root@ss-pc186 cpp]# cd /usr/src/rtlinux/rtlinux-3.1/examples/cpp/
[root@ss-pc186 cpp]# ls
app.o  hello.cpp  hello.o  Makefile  README  rtl_cpp.c  rtl_cpp.o
[root@ss-pc186 cpp]# make
g++ -D__KERNEL__ -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe
-march=3Di686 -DMODULE -DMODVERSIONS -include
/usr/src/rtlinux/linux/include/linux/modversions.h -g -D__RTL__
-D_LOOSE_KERNEL_NAMES -I/usr/src/rtlinux/rtlinux-3.1/linux/include
-I/usr/src/rtlinux/rtlinux-3.1/include
-I/usr/src/rtlinux/rtlinux-3.1/include/compat
-I/usr/src/rtlinux/rtlinux-3.1/include/posix -fno-exceptions -fno-rtti
-fno-use-cxa-atexit   -c -o hello.o hello.cpp
In file included from
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/system.h:305,
                 from
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/apic.h:6,
                 from
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/smp.h:22,
                 from
/usr/src/rtlinux/rtlinux-3.1/linux/include/linux/smp.h:14,
                 from /usr/src/rtlinux/rtlinux-3.1/include/rtl_core.h:21,
                 from /usr/src/rtlinux/rtlinux-3.1/include/rtl_sched.h:24=
,
                 from /usr/src/rtlinux/rtlinux-3.1/include/rtl_cpp.h:20,
                 from hello.cpp:1:
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:24:13:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:25:13:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:26:20:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:27:23:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:28:22:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:29:25:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:30:25:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:31:24:
warning: extra tokens at
end of #undef directive
/usr/src/rtlinux/rtlinux-3.1/linux/include/asm/rtlinux_cli.h:41:17:
warning: extra tokens at
end of #undef directive
ld -r -o app.o `g++ -print-file-name=3Dcrtbegin.o`  hello.o `g++
-print-file-name=3Dcrtend.o`
kgcc -D__KERNEL__ -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe
-march=3Di686 -DMODULE -DMODVERSIONS -include
/usr/src/rtlinux/linux/include/linux/modversions.h -g -D__RTL__
-D_LOOSE_KERNEL_NAMES -O2 -I/usr/src/rtlinux/rtlinux-3.1/linux/include
-I/usr/src/rtlinux/rtlinux-3.1/include
-I/usr/src/rtlinux/rtlinux-3.1/include/compat
-I/usr/src/rtlinux/rtlinux-3.1/include/posix   -c -o rtl_cpp.o rtl_cpp.c
[root@ss-pc186 cpp]# insmod rtl_cpp.o
[root@ss-pc186 cpp]# insmod app.o
[root@ss-pc186 cpp]# insmod hello.o
hello.o: unresolved symbol __do_global_ctors_aux
hello.o: unresolved symbol __do_global_dtors_aux
hello.o:
Hint: You are trying to load a module without a GPL compatible license
      and it has unresolved symbols.  Contact the module supplier for
      assistance, only they can help you.

Do you know how to solve this problem?
Thank you very much for your help.

Sincerely yours, Vasin






_______________________________________________
Rtl mailing list
[email protected]
http://hq.fsmlabs.com/mailman/listinfo/rtl
http:/www.rtlinux-gpl.org/