Undefined refrence to init and delay error

this is my code

#include <Arduino.h>
#include<Servo.h>
int pos=0;
Servo myservo;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(8);
}

void loop() {
  // put your main code here, to run repeatedly:
for(pos=0;pos<=180;pos++)
{
  myservo.write(pos);
  delay(15);
  }
  for(pos=180;pos>=0;pos--)
  {
    myservo.write(pos);
    delay(15);
  }

and for all other codes same exit status 1 error is shown
in function main
undefined refrence to init
undefined refrence to delay

Seems like the base Arduino framework has been corrupted. What platformio.ini are you using?

Also see Redirecting..., you need to write proper C++ code instead of Arduino INO code. Though that’s not yet the problem you’re having, first the upper must be solved.

Here is my platformio.ini
Platform=atmelavr
Board=nanoatmega328
Framework=arduino

Try removing C:\Users\<user>\.platformio\packages\framework-arduino-avr and retry compilation.

Nope its showing same error .

Are you sure you posted the right code? There’s a missing } at the end of the loop() function.

Also you saving this code inside of a .cpp file, yeah?

Yeah i am storing it under src in main.cpp file

I cannot reproduce this problem.

My platformio.ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
; servo library
lib_deps = 883

src\main.cpp

#include <Arduino.h>
#include<Servo.h>
int pos=0;
Servo myservo;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(8);
}

void loop() {
  // put your main code here, to run repeatedly:
for(pos=0;pos<=180;pos++)
{
  myservo.write(pos);
  delay(15);
  }
  for(pos=180;pos>=0;pos--)
  {
    myservo.write(pos);
    delay(15);
  }
}

Builds without problems

>pio run
Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR 2.2.0 > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES:
 - framework-arduino-avr 5.0.0
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Servo> 1.1.6
Building in release mode
Compiling .pio\build\nanoatmega328\src\main.cpp.o
[..]
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\nanoatmega328\libFrameworkArduino.a
Indexing .pio\build\nanoatmega328\libFrameworkArduino.a
Linking .pio\build\nanoatmega328\firmware.elf
Building .pio\build\nanoatmega328\firmware.hex
Checking size .pio\build\nanoatmega328\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.5% (used 52 bytes from 2048 bytes)
Flash: [=         ]   7.0% (used 2160 bytes from 30720 bytes)
===================== [SUCCESS] Took 2.80 seconds =====================

Can you post the exact error when compiling?

What version of arduino ide are you using ?

Arduino IDE? None is needed here, the PlatformIO doesn’t need the Arduino IDE. I’m building with PlatformIO from the commandline here.

My pio --version is the latest version 4.4.0a4 with the atmelavr platform being at 2.2.0.

So it seems there is a problem with linker as compilation always stops at
Linking .pio\build\nanoatmega328\firmware.elf
And shows the undefined refrence error

Well as I cannot reproduce that I don’t really know what’s going on.

I suggest you make sure to update PlatformIO to the latest version and update all platforms (see Updates in the project tasks).

Then make sure to copy the platformio.ini and main.cpp I have posted 1:1 in your project.

You can also remove all the folders within C:\Users\<user>\.platformio\packages\ so that the compiler and framework are freshly downloaded.

Sure this is my error

Does the file C:\Users\91789\platformio\packages\framework-arduino-avr\cores\arduino\wiring.c exist and contains the functions void delay(unsigned long ms) and void init()?

No but it does contain
Wiring_analog
Wiring_digital
Wiring _private
Wiring_pulse
Wiring_pulse
Wiring_shift
And also my code compiles after deletion anf fresh installation of framework_avr but it happens only onetime and after that it starts showing same error

Never in my life have I seen that before. What would cause the file to be deleted? Do you have an antivirus that blocks that .c file?

No because if there was something blocking it than it would have not compiled even one time .