none
Build Error "MSB4016" compiling Arduino C++ Source Code

    Question

  • Hi,

    i am currently developing some course material for my Course "Programming IOT Projects with C++ using Arduino Uno".

    Currently, i managed to successfully complete one projekt and tried to start another. Suddenly, i get a build error "MSB4016" (12 times !) with a simple project quite similar to the one i already successfully completed.

    Here is my code:

    #1: Siebensegment.h

    /*
    	Programming simple Controllers with C++
    	( no operating system )
    	Course example Semaphore
    
    	Created: March 10, 2017
    	Author: Gerhard Biebl
    */
    
    #pragma once
    
    //#define __DOLOOP // enables arduino loop function
    
    #include "arduino.h"
    #include <stdio.h>
    #include <stdlib.h>
    using namespace std;
    
    class Siebensegment
    {
    public:
    	Siebensegment();
    	Siebensegment(unsigned int* pPinnumbers);
    	~Siebensegment();
    	void setWert(unsigned int Wert);
    	void Siebensegment::InitPins();
    	void Siebensegment::InitPins(unsigned int* SemaphorePins);
    	static const int Pinnumber = 7;
    private:
    	unsigned int Wert;
    	static const int MaxValue = 16;
    	bool Segment[MaxValue][Pinnumber];
    	unsigned int* pins;		// an array of pin numbers
    };

    #2: Siebensegment.cpp

    /*
    	Programming simple Controllers with C++
    	( no operating system )
    	Course example Semaphore
    
    	Created: March 10, 2017
    	Author: Gerhard Biebl
    */
    
    #include "Siebensegment.h"
    
    // implementation of methods
    Siebensegment::Siebensegment()
    {
    	InitPins();
    }
    
    Siebensegment::Siebensegment(unsigned int* pPinnumbers)
    {
    	InitPins(pPinnumbers);
    }
    
    Siebensegment::~Siebensegment()
    {
    	delete pins;
    }
    
    void Siebensegment::InitPins()
    {
    	unsigned int* ppins = new unsigned int[Pinnumber] { 3, 4, 5, 6, 7, 8, 9 };
    	InitPins(ppins);
    }
    
    void Siebensegment::InitPins(unsigned int* SegmentPins)
    {
    	pins = new unsigned int[Pinnumber];
    	for (unsigned int index = 0; index<Pinnumber; index++)
    	{
    		pins[index] = SegmentPins[index];
    		pinMode(pins[index], OUTPUT);
    	}
    	delete[] SegmentPins;
    
    	// Schaltzustände der einzelnen Segmente für jede Zahl
    
    	// 0
    	Segment[0][0] = HIGH;
    	Segment[0][1] = HIGH;
    	Segment[0][2] = HIGH;
    	Segment[0][3] = HIGH;
    	Segment[0][4] = HIGH;
    	Segment[0][5] = HIGH;
    	Segment[0][6] = LOW;
    
    	// 1
    	Segment[1][0] = LOW;
    	Segment[1][1] = HIGH;
    	Segment[1][2] = HIGH;
    	Segment[1][3] = LOW;
    	Segment[1][4] = LOW;
    	Segment[1][5] = LOW;
    	Segment[1][6] = LOW;
    
    	// 2
    	Segment[2][0] = HIGH;
    	Segment[2][1] = HIGH;
    	Segment[2][2] = LOW;
    	Segment[2][3] = HIGH;
    	Segment[2][4] = HIGH;
    	Segment[2][5] = LOW;
    	Segment[2][6] = HIGH;
    
    	// 3
    	Segment[3][0] = HIGH;
    	Segment[3][1] = HIGH;
    	Segment[3][2] = HIGH;
    	Segment[3][3] = HIGH;
    	Segment[3][4] = LOW;
    	Segment[3][5] = LOW;
    	Segment[3][6] = HIGH;
    
    	// 4
    	Segment[4][0] = LOW;
    	Segment[4][1] = HIGH;
    	Segment[4][2] = HIGH;
    	Segment[4][3] = LOW;
    	Segment[4][4] = LOW;
    	Segment[4][5] = HIGH;
    	Segment[4][6] = HIGH;
    
    	// 5
    	Segment[5][0] = HIGH;
    	Segment[5][1] = LOW;
    	Segment[5][2] = HIGH;
    	Segment[5][3] = HIGH;
    	Segment[5][4] = LOW;
    	Segment[5][5] = HIGH;
    	Segment[5][6] = HIGH;
    
    	// 6
    	Segment[6][0] = HIGH;
    	Segment[6][1] = LOW;
    	Segment[6][2] = HIGH;
    	Segment[6][3] = HIGH;
    	Segment[6][4] = HIGH;
    	Segment[6][5] = HIGH;
    	Segment[6][6] = HIGH;
    
    	// 7
    	Segment[7][0] = HIGH;
    	Segment[7][1] = HIGH;
    	Segment[7][2] = HIGH;
    	Segment[7][3] = LOW;
    	Segment[7][4] = LOW;
    	Segment[7][5] = LOW;
    	Segment[7][6] = LOW;
    
    	// 8
    	Segment[8][0] = HIGH;
    	Segment[8][1] = HIGH;
    	Segment[8][2] = HIGH;
    	Segment[8][3] = HIGH;
    	Segment[8][4] = HIGH;
    	Segment[8][5] = HIGH;
    	Segment[8][6] = HIGH;
    
    	// 9
    	Segment[9][0] = HIGH;
    	Segment[9][1] = HIGH;
    	Segment[9][2] = HIGH;
    	Segment[9][3] = HIGH;
    	Segment[9][4] = LOW;
    	Segment[9][5] = HIGH;
    	Segment[9][6] = HIGH;
    
    	// a
    	Segment[10][0] = HIGH;
    	Segment[10][1] = HIGH;
    	Segment[10][2] = HIGH;
    	Segment[10][3] = HIGH;
    	Segment[10][4] = HIGH;
    	Segment[10][5] = LOW;
    	Segment[10][6] = HIGH;
    
    	// b
    	Segment[11][0] = LOW;
    	Segment[11][1] = LOW;
    	Segment[11][2] = HIGH;
    	Segment[11][3] = HIGH;
    	Segment[11][4] = HIGH;
    	Segment[11][5] = HIGH;
    	Segment[11][6] = HIGH;
    
    	// c
    	Segment[12][0] = LOW;
    	Segment[12][1] = LOW;
    	Segment[12][2] = LOW;
    	Segment[12][3] = HIGH;
    	Segment[12][4] = HIGH;
    	Segment[12][5] = LOW;
    	Segment[12][6] = HIGH;
    
    	// d
    	Segment[13][0] = LOW;
    	Segment[13][1] = HIGH;
    	Segment[13][2] = HIGH;
    	Segment[13][3] = HIGH;
    	Segment[13][4] = HIGH;
    	Segment[13][5] = LOW;
    	Segment[13][6] = HIGH;
    
    	// e 
    	Segment[14][0] = HIGH;
    	Segment[14][1] = HIGH;
    	Segment[14][2] = LOW;
    	Segment[14][3] = HIGH;
    	Segment[14][4] = HIGH;
    	Segment[14][5] = HIGH;
    	Segment[14][6] = HIGH;
    
    	// f
    	Segment[15][0] = HIGH;
    	Segment[15][1] = LOW;
    	Segment[15][2] = LOW;
    	Segment[15][3] = LOW;
    	Segment[15][4] = HIGH;
    	Segment[15][5] = HIGH;
    	Segment[15][6] = HIGH;
    
    }
    void Siebensegment::setWert(unsigned int Wert)
    {
    	if (Wert < 16)
    	{
    		this->Wert = Wert;
    		for (int pinindex = 0; pinindex < Pinnumber; pinindex++)
    		{
    			digitalWrite(pins[pinindex], Segment[Wert][pinindex]);
    		}
    	}
    }

    #3: Siebensegment.ino

    /*
    	Programming simple Controllers with C++
    	( no operating system )
    	Course example Semaphore
    
    	Created: March 10, 2017
    	Author: Gerhard Biebl
    */
    
    #include "Siebensegment.h"
    
    unsigned int* pNumbers = new unsigned int[Siebensegment::Pinnumber] { 3, 4, 5, 6, 7, 8, 9 };
    static Siebensegment SSDisplay(pNumbers);
    
    void setup()
    {
    	SSDisplay.setWert(0);
    }
    
    inline void loop()
    {
    }

    The error messgae:

    Schweregrad	Code	Beschreibung	Projekt	Datei	Zeile	Unterdrückungszustand
    Fehler	MSB4018	Unerwarteter Fehler bei der VCMessage-Aufgabe.
    System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
       at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.Format(IFormatProvider provider, String format, Object[] args)
       at Microsoft.Build.Shared.ResourceUtilities.FormatString(String unformatted, Object[] args)
       at Microsoft.Build.Utilities.TaskLoggingHelper.FormatString(String unformatted, Object[] args)
       at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args)
       at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs)
       at Microsoft.Build.CPPTasks.VCMessage.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	Siebensegment	C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets	57	
    

    I am using Visual Studio 2015 Community Edition with current Arduino IDE Plugin.

    I simply can see no difference to my first project, but i assume it has to do with some incompatibility between the C++ IOT Project templates and the Arduino project templates (maybe ?) since the first project i started with VS Arduino IOT project template (deleting all unnecessary muck for my simplified examples) while the second i made using the Arduino IDE plugin "new arduino project" template.

    I cannot use VS IOT Project templates, because i use a somewhat downscaled Arduino UNO board clone without any additional shields.

    Please spre me with comments such as "Why not better use C?" and the such. I definitely want to use "C++" because "C" sucks (in my opinion).

    I would appreciate some help with this.

    Cheers !

    Gerhard Biebl




    Gerhard Biebl

    Friday, March 10, 2017 1:37 PM

Answers