Verify C++ support with CodeSourcery

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4016 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-10-03 21:10:11 +00:00
parent d174e457ab
commit fa313aa47f
4 changed files with 62 additions and 16 deletions

View File

@ -46,6 +46,9 @@ SUBDIRS = buttons dhcpd ftpc hello helloxx hidkbd igmp lcdrw mm mount \
CNTXTDIRS =
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
CNTXTDIRS += helloxx
endif
ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y)
CNTXTDIRS += lcdrw
endif

View File

@ -131,24 +131,42 @@ examples/hello
^^^^^^^^^^^^^^
This is the mandatory, "Hello, World!!" example. It is little more
than examples/null with a single printf statement. Again useful only
than examples/null with a single printf statement. Really useful only
for bringing up new NuttX architectures.
NuttX configuration settings:
CONFIG_EXAMPLE_HELLOXX_NOSTATICCONST - Set if system does not support
static constructors.
CONFIG_EXAMPLE_HELLOXX_NOSTACKCONST - Set if the systgem does not
support constructionof objects on the stack.
examples/helloxx
^^^^^^^^^^^^^^^^
This is C++ version of the "Hello, World!!" example. It is intended
only to verify that the C++ compiler is function, that basic C++
only to verify that the C++ compiler is functional, that basic C++
library suupport is available, and that class are instantiated
correctly.
NuttX configuration settings:
CONFIG_EXAMPLES_HELLOXX_BUILTIN -- Build the helloxx example as a
"built-in" that can be executed from the NSH command line.
CONFIG_EXAMPLE_HELLOXX_NOSTATICCONST - Set if system does not support
static constructors.
CONFIG_EXAMPLE_HELLOXX_NOSTACKCONST - Set if the system does not
support construction of objects on the stack.
Also needed:
CONFIG_HAVE_CXX=y
And you may have to tinker with the following to get libxx to compile
properly:
CONFIG_CXX_NEWLONG=y or =n
The argument of the 'new' operators should take a type of size_t. But size_t
has an unknown underlying. In the nuttx sys/types.h header file, size_t
is typed as uint32_t (which is determined by architecture-specific logic).
But the C++ compiler may believe that size_t is of a different type resulting
in compilation errors in the operator. Using the underlying integer type
Instead of size_t seems to resolve the compilation issues.
examples/hidkbd
^^^^^^^^^^^^^^^^

14
examples/helloxx/Makefile Executable file → Normal file
View File

@ -58,6 +58,12 @@ endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = helloxx
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
@ -92,7 +98,13 @@ $(CXXOBJS): %$(OBJEXT): %.cxx
done ; )
@touch .built
context:
.context:
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

25
examples/helloxx/main.cxx Executable file → Normal file
View File

@ -60,12 +60,12 @@ class CHelloWorld
{
if (mSecret != 42)
{
printf("CONSTRUCTION FAILED!\n");
printf("CHelloWorld::HelloWorld: CONSTRUCTION FAILED!\n");
return false;
}
else
{
printf("Hello, World!!\n");
printf("CHelloWorld::HelloWorld: Hello, World!!\n");
return true;
}
};
@ -90,23 +90,36 @@ static CHelloWorld g_HelloWorld;
// user_start
//***************************************************************************
int user_start(int argc, char *argv[])
/****************************************************************************
* Name: user_start/nxhello_main
****************************************************************************/
#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN
extern "C" int helloxx_main(int argc, char *argv[]);
# define MAIN_NAME helloxx_main
# define MAIN_STRING "helloxx_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
int MAIN_NAME(int argc, char *argv[])
{
#ifndef CONFIG_EXAMPLE_HELLOXX_NOSTACKCONST
CHelloWorld HelloWorld;
#endif
CHelloWorld *pHelloWorld = new CHelloWorld;
printf("Saying hello from the dynamically constructed instance\n");
printf(MAIN_STRING "Saying hello from the dynamically constructed instance\n");
pHelloWorld->HelloWorld();
#ifndef CONFIG_EXAMPLE_HELLOXX_NOSTACKCONST
printf("Saying hello from the statically constructed instance\n");
printf(MAIN_STRING "Saying hello from the statically constructed instance\n");
HelloWorld.HelloWorld();
#endif
#ifndef CONFIG_EXAMPLE_HELLOXX_NOSTATICCONST
printf("Saying hello from the statically constructed instance\n");
printf(MAIN_STRING "Saying hello from the statically constructed instance\n");
g_HelloWorld.HelloWorld();
#endif