Build error problem with c++ file

Thread Starter

hunterage2000

Joined May 2, 2010
487
I am trying to clean and build the attached .cpp file but I am getting errors which I don't understand. I have created a c++ main file in MPLAB but it is seeing errors with:

#include <cstdlib> which is supposed to be the same as <stdlib.h>

and

using namespace std;

Can anyone help?
 

Attachments

Thread Starter

hunterage2000

Joined May 2, 2010
487
Not sure. When I create a new C main file the code shows:

Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {

    return (EXIT_SUCCESS);
}
When you clean and build it as it is there is no problems but when I create a C++ file and do the same it gives errors for the #include <cstdlib> and using namespace std.
 

ErnieM

Joined Apr 24, 2011
7,996
I was a little curious so I downloaded the XC32++ compiler, created a dummy project a and main cpp file. The default main cpp gave me the exact code you posted.

And then it built just fine with no changes.

Code:
/*
* File:   newmain.cpp
* Author: ErnieM
*
* Created on May 31, 2015, 8:18 AM
*/

#include <cstdlib>

using namespace std;

/*
*
*/
int main(int argc, char** argv) {

    return 0;
}
 

DumboFixer

Joined Feb 10, 2009
217
Looking at the output you have the following:

Code:
make[2]: *** No rule to make target 'build/default/production/neimain.o', needed by 1dist/default/production/Blink_pin.X.production.hex'. Stop,
make[1J: *** [.build-conf] Error 2
make: *** I.build-implJ Brror 2
To me that says you have something wrong with your makefile as it doesn't know how to make neimain.o
 

Thread Starter

hunterage2000

Joined May 2, 2010
487
When you create a new project there is no option to choose the type. You just add new file to the project in the project window. I am using xc8 compiler, maybe you can't use c++ with it or you might have to edit the makefile. Not sure.
 

ErnieM

Joined Apr 24, 2011
7,996
I'm sure. Use the menu and click File | New Project and follow the wizard.

When you get to Select Compiler check the version that supports C++. That's xc32 v 1.34 on my computer.
 
Top