1

I am using a MacBook, if that helps, and running this code through Terminal.(It is literally just clicking the Build and Run button in CodeBlocks and having the results displayed in Terminal such as "print out a message" or "running a for loop" ).

I only pressed "Build and run" (F9) in CodeBlocks and I got these errors and weird messages.

Click to see error Click to see CodeBlocks glitch

(Right after I hit "yes" , it displayed

this error )

Why doesn't this run?

I'm really confused. Can someone explain what needs to be changed in order for it to execute the constructor for the Burrito object I just created in the main.cpp file?

I compile by using the Build and Run button in CodeBlocks. I don't know any other method of running the program.

Click to see how I build and run/compile


//main.cpp

#include <iostream>
#include "Burrito.h"
using namespace std;

int main()
{
    Burrito bo;
    return 0;
}

//Burrito.h

#ifndef BURRITO_H
#define BURRITO_H


class Burrito
{
    public:
        Burrito();

};

#endif // BURRITO_H

// Burrito.cpp

#include "Burrito.h"
#include <iostream>
using namespace std;



Burrito::Burrito()
{
    cout << "hey now " << endl;
}

Error message:

Undefined symbols for architecture x86_64:
  "Burrito::Burrito()", referenced from:
      _main in main.o


ld: symbol(s) not found for architecture x86_64


clang: error: linker command failed with exit code 1 (use -v to see invocation)


Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Enoch Lu
  • 37
  • 2
  • I'm not sure I'd call that information window a "glitch." What happened when hit "yes" that you did want to try building the file? – scohe001 Aug 06 '19 at 19:51
  • When I hit yes, it gave me this Error message: Undefined symbols for architecture x86_64: "Burrito::Burrito()", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Process terminated with status 1 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s)) – Enoch Lu Aug 06 '19 at 19:53
  • If it helps, Scohe001, I put the error message more clearly at the very bottom of the post. – Enoch Lu Aug 06 '19 at 19:54
  • Nothing is weird about the output and the popup window. You code did not successfully compile and link because the linker said you don't have `Burrito::Burrito()` defined. I assume `Burrito.cpp` is not being compiled as part of your project. – drescherjm Aug 06 '19 at 20:04
  • 1
    Did you save `Burrito.cpp`? From the ***Click to see how I build and run/compile*** link the picture showed a star next to `Burrito.cpp` meaning the file has not been saved since it was last changed. Perhaps that is the real issue. You could be compiling an old version of `Burrito.cpp` before you added the definition of the constructor. – drescherjm Aug 06 '19 at 20:06
  • You've asked this question before, https://stackoverflow.com/questions/57349728/undefined-symbols-for-architecture-x86-64-object-wont-execute-constructor The answer now is the same as the answer before. You aren't building your program correctly. You need to add Burrito.cpp to your code blocks project, you need to save the file before you compile. You also need to read the documentation. – john Aug 06 '19 at 20:14
  • 1
    Here's a quote from Code Blocks documentation *In CodeBlocks, the sources and the settings for the build process are stored in a project file .cbp. C/C++ sources and the corresponding header files are the typical components of a project. The easiest way to create a new project is executing the command ’File’ /’Project’ and selecting a wizard. Then you can add files to the project via the context menu ’Add files’ in the Management window.* It's the 'Add files' part you are missing. You must add the Burrito.cpp file to your project. – john Aug 06 '19 at 20:17
  • 1
    [This question has the answers you need](https://stackoverflow.com/q/5971206/1270789), specific to Code::Blocks. – Ken Y-N Aug 07 '19 at 00:39

0 Answers0