How to createa C++ project?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to createa C++ project?

1,691 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by olk on Sun Oct 28 12:32:53 MST 2012
Hi,
I tried to create an C++ project for LPC 1100/1200 (IDE v4.2.3, build 255, 30/05/2012):
File -> New -> Project... ->  'New Projekt' dialog
I selected 'LPCExpresso C++ Project' but unfortunately I got no wizard for the several listed MCUs ('NEXT' button is disabled)?!
The same happens if I try 'C++ Project' -> from the 'New Projekt' dialog - no option enables the 'NEXT' button.

I did not found any hint in 'Getting started with NXP LPCXpresso' pdf how to create an C++ project for LPC boards.

Seams to me that C++ projects can't be created with CodeRed Eclipse for LPCExoresso?!

regards,
Oliver
0 Kudos
Reply
14 Replies

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by AndrewCapon on Fri Jun 28 04:42:27 MST 2013
Thanks fjrg76, you save me a load of arseing around.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Nov 13 18:47:10 MST 2012
There is not such a restriction, you can compile C++ projects inside the (Free Editon) LPCXpresso ;)
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JAlvarez on Tue Nov 13 18:42:09 MST 2012
Restricting the 128K free LPCXpreso IDE to only C programs (no C++) is a significant limitation. The Arduino and mbed libraries are good examples of how C++ wrappers can simplify embedded development. Restricting download code size on the free IDE is probably reasonable, but restricting the programming language is not.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Nov 01 15:39:34 MST 2012

Quote: ArtjomGromak
That is wrong?



Wrong library: Newlib(none) ;)
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Nov 01 15:33:56 MST 2012
Those errors are related with the C library you're using, and are not particularly related with math library. Try with "printf" and I'm pretty shure you'll get the same errors.


The linker must be said which library your project is going to use. There are several libraries that you can link your project against (outside LPCXpresso):

NewLib
uCLibC
RedLib (Red Code for the LPCXpresso)

(Google "c library for embedded")


In LPCXpresso (NewLib and RedLib):

Quickstart Panel -> Quick settings -> Set Library type. Try both but those that say "no host".




Quote: ArtjomGromak
Thanks, fjrg76.
I tried create objects in your project - it's work.
But if I try use math functions project don't builded.
This is my function:
#include <math.h>

volatile float X, Y, Z;

void test_math() {
     {
    float x=X, y=Y;
        x=x*sqrtf(y);
        Z=x+y*y;
    }
}




Console:

That is wrong?

0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Thu Nov 01 14:44:59 MST 2012

Quote: fjrg76
Of course I will

Be aware of these facts:




Thanks, fjrg76.
I tried create objects in your project - it's work.
But if I try use math functions project don't builded.
This is my function:
#include <math.h>

volatile float X, Y, Z;

void test_math() {
     {
    float x=X, y=Y;
        x=x*sqrtf(y);
        Z=x+y*y;
    }
}


Console:

Quote:

Building target: pruebacpp.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -Xlinker -Map="pruebacpp.map" -Xlinker --gc-sections -mcpu=cortex-m0 -mthumb -T "pruebacpp_Release.ld" -o"pruebacpp.axf"  ./startup/aeabi_romdiv_patch.o ./startup/cr_startup_lpc12xx.o  ./src/core_cm0.o ./src/main.o ./src/system_LPC122x.o  
c:/nxp/lpcxpresso_4.3.0_1023/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib/armv6-m\libc.a(lib_a-abort.o): In function `abort':
abort.c:(.text+0xa): undefined reference to `_exit'
c:/nxp/lpcxpresso_4.3.0_1023/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib/armv6-m\libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text+0xe): undefined reference to `_kill'
c:/nxp/lpcxpresso_4.3.0_1023/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib/armv6-m\libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text+0x2a): undefined reference to `_getpid'
c:/nxp/lpcxpresso_4.3.0_1023/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib/armv6-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0xc): undefined reference to `_sbrk'
collect2: ld returned 1 exit status
make: *** [pruebacpp.axf] Error 1


That is wrong?
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Nov 01 11:08:54 MST 2012

Quote: ArtjomGromak
[B]fjrg76[/B] can you get sample C++ project for LPCXpresso?
Thanks.




Of course I will

Be aware of these facts:

1.- I couldn't link the projects that already existed in the workspace to the C++ project (CMSIS), so I took the easiest path (and the most ugly one): I copied all the required files into the /src directory ... awful ... but it works =)

LPCXpresso allows you to create only an empty project when choosing C++ projects.

2.- The ISR handlers must be enclosed in "extern "C"{}" blocks; otherwise the linker won't find them. This step is necessary because we're mixing C and C++ code, and the ISRs code are marked as "weak". In fact, the theory says that all C functions that are going to be compiled and linked using C++ must be marked as "extern "C"{}" blocks. So far, I 've done this only on ISRs.

3.- I made this project for a LPC1227 board of my own. So you must create a new LPCXpresso C++ project for your uC, and once it has been created then copy to your /src directory all files (without directory structure) that are in the CMSISv2p00_XXX folder:


-rw-r--r--    1 Administ Administ    50993 May 27  2011 LPC122x.h
-rw-r--r--    1 Administ Administ     1674 May 27  2011 LPC12xx.h
-rw-r--r--    1 Administ Administ     7590 May 27  2011 core_cm0.c
-rw-r--r--    1 Administ Administ    30089 Jun  2  2011 core_cm0.h
-rw-r--r--    1 Administ Administ    22142 May 27  2011 core_cmFunc.h
-rw-r--r--    1 Administ Administ    20993 May 27  2011 core_cmInstr.h
-rw-r--r--    1 Administ Administ     1791 Nov  1 08:52 main.cpp
-rw-r--r--    1 Administ Administ    19061 Nov  1 01:57 system_LPC122x.c
-rw-r--r--    1 Administ Administ     2063 May 27  2011 system_LPC122x.h
-rw-r--r--    1 Administ Administ     1716 May 27  2011 system_LPC12xx.h




Let me know if this works for you.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Nov 01 10:45:47 MST 2012

Quote: frame
That depends.
In my day job I develop software for a mass market product.
You should hear our project management's and controlling department's
reaction on suggesting some cents more, because you would like to use C++.



Yep, it's not easy to adopt C++ for currently projects, but that no means C++ is that bad =)


Quote:

We currently use PIC18F with 512/1024 byte of RAM, so we even avoid using clib ...



Through your point of view it would be impossible not only to use C++ but also to include in our projects other tools like an RTOS.

But take into account that the most humble Cortex-M uC has at least 8K RAM, and in this forum all we are talking about Cortex technology, so to mention PICs here is pointless. Besides, PICs are not meant to be programmed in C

Such a ammount of resources in Cortex-m uC lets us to programm even in C++, and to include an RTOS, and more important, to have a layered architecture.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Wed Oct 31 12:21:04 MST 2012

Quote:
Hi Frame

In fact, this is a good idea =)

That depends.
In my day job I develop software for a mass market product.
You should hear our project management's and controlling department's
reaction on suggesting some cents more, because you would like to use C++.

We currently use PIC18F with 512/1024 byte of RAM, so we even avoid using clib ...
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Wed Oct 31 05:13:03 MST 2012

Quote: fjrg76
Hi Frame

By the way, my C++ project in LPCXpresso 4.3.0 is up and running =)



[B]fjrg76[/B] can you get sample C++ project for LPCXpresso?
Thanks.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Oct 31 00:06:35 MST 2012
Hi Frame

In fact, this is a good idea =)

Most people is afraid of using C++ because they think it is a resources killer ... and they might be right in one sense... but in the other sense, C++ is not that bad. Of course if you try to use STL, exceptions, indiscriminated use of polymorphysm, and so on, then you'll eat all your uC resources. But, what is Object Oriented Programming? Nothing but a hi-level abstractions of real-life problems. We can model the real life using only abstractions, encapsulation, and inheritance, and nothing more. STL and exceptions are extensions of the language, so we can avoid them.

Applications written in C++ are more elegant than those written in plain C.


By the way, my C++ project in LPCXpresso 4.3.0 is up and running =)
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Tue Oct 30 23:55:30 MST 2012
I'm not sure if a C++ project for a LPC1000 uC is such a good idea.
You are going to find out.
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Oct 30 23:06:25 MST 2012
LPCXpresso 4.3.0 allows you to create a project in C++. However, all you get is an empty C++ project that must be filled by hand.

It becomes a nightmare when trying to add the CMSIS and FreeRTOS support, 'cause the compiler can't found them, even when they reside in the same workspace. This is all I could got after trying several hours:

[FONT=Courier New]make all
Building file: ../src/main.cpp
Invoking: MCU C++ Compiler
arm-none-eabi-c++ -D__NEWLIB__ -DDEBUG -D__CODE_RED -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -fno-rtti -mcpu=cortex-m0 -mthumb -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp

Building target: pruebacpp.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -Xlinker -Map="pruebacpp.map" -Xlinker --gc-sections -mcpu=cortex-m0 -mthumb -T "pruebacpp_Debug.ld" -o"pruebacpp.axf"  ./src/core_cm0.o ./src/main.o ./src/system_LPC122x.o  
c:/nxp/lpcxpresso_4.3.0_1023/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol ResetISR; defaulting to 00000000
Finished building target: pruebacpp.axf

make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "pruebacpp.axf"; # arm-none-eabi-objcopy -O binary "pruebacpp.axf" "pruebacpp.bin" ; checksum -p LPC1227_301 -d "pruebacpp.bin";
   text   data    bss    dec    hexfilename
    136      0      4    140     8cpruebacpp.axf
[/FONT]


As you can see this warning is saying that I did something wrong:

[FONT=Courier New]ld.exe: warning: cannot find entry symbol ResetISR; defaulting to 00000000[/FONT]


I guess I'm gonna give up and try other options, like CooCox (This platform doesn't support C++ in a native way, however, it was easier to set it up).
0 Kudos
Reply

1,319 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by olk on Sun Oct 28 12:53:21 MST 2012
OK - I can answer myself:
'The entry-level NXP focussed product is the LPCXpresso IDE, which  supports C development (not C++) for the NXP LPC1000 family of MCUs' - very disappointing (was not mentioned on the several websites from embedded artists).
So I'm forced to write the code in C or to drop CodeRed IDE.
Maybe I should stick on the command-line tools like vi, make etc.
0 Kudos
Reply