Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

C++ derleme sorunu

Başlatan robikod, 02 Ocak 2020, 10:47:59

robikod

STM32'de C kodu kullanıyorum ve bu kodlar içerisinde C++ kodu da kullanmam gerekti. Bununla ilgili githubda şu şekilde bir örnek buldum. https://github.com/iancanada/STM32Cube-Cpp-programming-example

Burada .cpp uzantılı bir dosya açıp burada gösterildiği gibi düzenledim. Daha sonra main.c 'de de çağırdım ancak birçok hata aldım. Konuyu yazan kişiye mail attım malese geri dönüş olmadı. Bu konuda yardımcı olabilecek var mı bu sorunu nasıl düzeltebilirim?

Src/main.c:224:1: error: unknown type name 'CLed'
Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f429xx.h:1268:29: error: expected declaration specifiers or '...' before '(' token
Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:115:36: error: expected declaration specifiers or '...' before '(' token
Src/main.c:224:44: error: expected declaration specifiers or '...' before numeric constant
Src/main.c:225:1: error: unknown type name 'CLed'
Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f429xx.h:1268:29: error: expected declaration specifiers or '...' before '(' token
Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:114:36: error: expected declaration specifiers or '...' before '(' token
Src/main.c:225:44: error: expected declaration specifiers or '...' before numeric constant
Src/main.c:226:1: error: unknown type name 'CLed'
Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f429xx.h:1268:29: error: expected declaration specifiers or '...' before '(' token
Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:116:36: error: expected declaration specifiers or '...' before '(' token
Src/main.c:226:44: error: expected declaration specifiers or '...' before numeric constant
Src/main.c:227:1: error: unknown type name 'CLed'
Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f429xx.h:1268:29: error: expected declaration specifiers or '...' before '(' token
Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:117:36: error: expected declaration specifiers or '...' before '(' token
Src/main.c:227:44: error: expected declaration specifiers or '...' before numeric constant


Daha sonra farklı olarak şunu denedim: .cpp içerisi şu şekilde:

CLed::CLed(GPIO_TypeDef* port,uint16_t pin,uint16_t toggleTime)
{
  _port=port;
  _pin=pin;
  _toggleTime=toggleTime;
  counter=0; 
  off();	
}

void CLed::runToggle()
{
  if(++counter>=_toggleTime)
  {
    counter=0;
    toggle();
  }	
}

void doSomething(void){
CLed led3(GPIOD,GPIO_PIN_13,500);
CLed led4(GPIOD,GPIO_PIN_12,1000);
CLed led5(GPIOD,GPIO_PIN_14,2000);
CLed led6(GPIOD,GPIO_PIN_15,4000);

  
}


doSomething() fonksiyonunu da main.c de çağırdım. O zamanda şu şekilde bir hata aldım ( fonksiyonu header dosyasına ekledim)


Inc/blankCpp.hpp:7:1: error: unknown type name 'class'
Inc/blankCpp.hpp:8:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
make: *** [build/main.o] Error 1


robikod

#2
Alıntı yapılan: JKramer - 02 Ocak 2020, 10:58:53https://isocpp.org/wiki/faq/mixing-c-and-cpp

Şimdi şu şekilde denedim, main.c'de hiç bir şekilde .hpp çağırmadan;

.cpp dosyasında

extern "C" void doSomething(void); yaptım.

Daha sonra, main.c de gidip header kısmında void doSomething(void); ekledim.

Daha sonra main loopta bu fonksiyonu çağırdım, şu hatayı aldım:


main.c:265: undefined reference to `doSomething'


taydin

C dosyasına koyman lazım extern "C" tanımını:


/* Bu dosya bir C dosyasi */
.
.
.

extern "C" {
   int some_cpp_function(int a);
}

.
.
.

int main(void)
{
    some_cpp_function(3);
}
Timur Aydın (mekatronik.org)

e-zeki

Hocam Keil de mi CubeIDE'de mi derliyorsun? kodu  C++ da derledin mi yoksa hala C99 Modda mı derliyorsun?