Topic : Unable to compile C++ project...

Forum : ARM

Original Post
Post Information Post
May 24, 2010 - 10:38pm
Guest

Hello all,

after numerous attempts I'm still not able to compile a C++ project under Ride7 (I'm using Windows XP). I know that C++ isn't officialy supported by the IDE, but in this post:

http://www.stm32circle.com/forum/viewtopic.php?id=433

VincentC gave some indications in order to compile a C++ project under Ride (above all, using libstdc++).
Unfortunately the linker gives me these error messages:

Code:

Building C:\Documents and Settings\.... 
 Running: LD 
 "C:\Programmi\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -
mthumb -Wl,-T -Xlinker "out\FW FAS.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -
nostartfiles -Wl,-Map -Xlinker "lst\FW FAS.map" -Wl,--warn-once  -Wl,-lstdc++ 
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-abort.o): In function `abort':  
 abort.c:(.text+0x8): undefined reference to `_exit'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_getpid_r':  
 signalr.c:(.text+0x2): undefined reference to `_getpid'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_kill_r':  
 signalr.c:(.text+0x1c): undefined reference to `_kill'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-writer.o): In function `_write_r':  
 writer.c:(.text+0x16): undefined reference to `_write'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-closer.o): In function `_close_r':  
 closer.c:(.text+0x12): undefined reference to `_close'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-fstatr.o): In function `_fstat_r':  
 fstatr.c:(.text+0x14): undefined reference to `_fstat'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-isattyr.o): In function `_isatty_r':  
 isattyr.c:(.text+0x12): undefined reference to `_isatty'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-lseekr.o): In function `_lseek_r':  
 lseekr.c:(.text+0x16): undefined reference to `_lseek'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-
none-eabi/lib/thumb2\libc.a(lib_a-readr.o): In function `_read_r':  
 readr.c:(.text+0x16): undefined reference to `_read'  
 collect2: ld returned 1 exit status  
  
Build failed

Note the numerous "undefined reference ...".
Anyone can help me?

Replies
Post Information Post
+1
0
-1
May 26, 2010 - 5:39pm
Guest

Hi

The error message listed above might not come from the fact that you are compiling a c++ project.
I suggest you make a trial with a basic project simply defining a class, initializing it and change its value.
This should shows that you did everything to make the use of c++ projects possible.

The error messages in your post are more related to symbols definition mismatch due to te use of a kind of printf or malloc function.
I think adding into your project the sources from C:\Program Files\Raisonance\ride\lib\ARM\std_sbrk
might resolve the problem.

Regards
Matloub

+1
0
-1
May 27, 2010 - 1:58pm
Guest

matloub wrote:
Hi

The error message listed above might not come from the fact that you are compiling a c++ project.
I suggest you make a trial with a basic project simply defining a class, initializing it and change its value.
This should shows that you did everything to make the use of c++ projects possible.

Hi Matloub, thanks for your answer!

Well, I've tried your suggestion to make a very simple cpp project, but the problem seems to be residing in the use of C++.
Suppose we have the following simple class, "Prova", which has a field and a constructor:

Prova.h

class Prova {

    public:
        
        int valore;
    
        Prova(int val);
};

Prova.cpp

#include "Prova.h"

Prova::Prova(int val) {
    this->valore = val;
}

The main is this:

#include "Prova.h"

int main() {
   Prova p1(2);
}

When compiling the above code, the linker gives me this output:


[...]

Building C:\Documents and Settings\....
 Running: LD 
 "C:\Programmi\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker "C:\Documents and Settings\francesco.lettich\Documenti\Progetti\Prosa\ProvaCPP\ProvaCPP.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "C:\Documents and Settings\francesco.lettich\Documenti\Progetti\Prosa\ProvaCPP\ProvaCPP.map"   -lstdc++ 
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-abort.o): In function `abort':  
 abort.c:(.text+0x8): undefined reference to `_exit'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_getpid_r':  
 signalr.c:(.text+0x2): undefined reference to `_getpid'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_kill_r':  
 signalr.c:(.text+0x1c): undefined reference to `_kill'  
 c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':  
 sbrkr.c:(.text+0x12): undefined reference to `_sbrk'  
 collect2: ld returned 1 exit status  
  
Build failed 

An interesting thing is that, if I comment the line contaning the instantiation of the "Prova" object, then everything goes fine!

About your other suggestion regarding std_sbrk:

Quote:
The error messages in your post are more related to symbols definition mismatch due to te use of a kind of printf or malloc function.
I think adding into your project the sources from C:\Program Files\Raisonance\ride\lib\ARM\std_sbrk
might resolve the problem.

Regards
Matloub

This seemed to help a bit. In fact, if I copy the sources of that directory in the directory of my sources, then I have only this error message:


[...]

Building C:\Documents and Settings\...
 Running: LD 
 "C:\Programmi\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker "out\FW FAS.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "lst\FW FAS.map" -Wl,--warn-once  -Wl,-lstdc++ 
 out\write.o: In function `_write':  
 write.c:(.text._write+0xe): undefined reference to `__io_putchar'  
 collect2: ld returned 1 exit status  

Do you have other suggestions?
Thanks :)

+1
0
-1
May 28, 2010 - 3:27pm
Guest

Okay, I answer to myself: it is necessary to write a source which implements all the missing functions reported by the linker, in order to link correctly lib.c. Here's explained why:

http://embdev.net/topic/177530

Here's an incomplete (bit good) example of what to include in a project:
http://www.coocox.net/show_comp.php?id=129

Other examples of a syscall.c can be found here:
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/

Anyway, there are still problems if I want to compile a CPP project. In fact, if I try to instantiate an object (DigitalState in this case) in "main", now the linker gives me these error messages:

Building C:\Documents and Settings\....
 Running: LD 
 "C:\Programmi\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker "out\FW FAS.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "lst\FW FAS.map" -Wl,--warn-once  -Wl,-lstdc++ 
 out\DigitalState.o: In function `DigitalState::LEDInit(Led_TypeDef)':  
 DigitalState.cpp:(.text._ZN12DigitalState7LEDInitE11Led_TypeDef+0x1a): undefined reference to `RCC_APB2PeriphClockCmd'  
 DigitalState.cpp:(.text._ZN12DigitalState7LEDInitE11Led_TypeDef+0x44): undefined reference to `GPIO_Init'  
 collect2: ld returned 1 exit status  

The only solution I've found was to switch completely to GCC 4.4.1 + makefile based project + Eclipse(for editing)).

Bye!

+1
0
-1
April 27, 2018 - 9:21am
halen mark

Such a great post to know different useful information.

https://logomines.com

+1
0
-1
July 10, 2018 - 10:40pm
peter Marker

Dell printer support number

https://printerchatsupport.co.uk/dell-printer-support/