Build error problem with c++ file

Discussion in 'Embedded Systems and Microcontrollers' started by hunterage2000, May 28, 2015.

  1. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    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?
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    don´t you have to state the namespace before you include the libraries?
     
  3. hunterage2000

    Thread Starter Active Member

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

    Code (Text):
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3.  
    4. int main(int argc, char** argv) {
    5.  
    6.     return (EXIT_SUCCESS);
    7. }
    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.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    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 (Text):
    1. /*
    2. * File:   newmain.cpp
    3. * Author: ErnieM
    4. *
    5. * Created on May 31, 2015, 8:18 AM
    6. */
    7.  
    8. #include <cstdlib>
    9.  
    10. using namespace std;
    11.  
    12. /*
    13. *
    14. */
    15. int main(int argc, char** argv) {
    16.  
    17.     return 0;
    18. }
    19.  
    20.  
     
  5. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    Looking at the output you have the following:

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

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    Did you first create a cpp project, or just a main.cpp?

    You need the project to set up the make file.
     
  7. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    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.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    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.
     
  9. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    It looks like only the PIC32 family can use C++.
     
Loading...