I"m do a rectangle program, separation in 3 files : rectangle.cppRectangle.h rectangleProgram.cppFirst i did the routine in one item without any kind of errors. Climate I break-up it and I acquired the complying with error :
Undefined signs for style x86_64: "Rectangle::setWidth(double)", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::setLength(double)", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::getPerimeters() const", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::getArea() const", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::getWidth() const", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::isSquare() const", referenced from: _main in rectangleProgram-4857c8.o "Rectangle::getLength() const", referenced from: _main in rectangleProgram-4857c8.old: symbol(s) not found for design x86_64

I have actually been spring through, yet can"t check out what i did wrong in spite of the fact it functioned in one piece (all with each other in one file) exactly how to fix this?Rectangle.h
1234567891011121314151617181920// Rectangle header file#ifndef RECTANGLE_H#define RECTANGLE_Hclass Rectangleprivate: dual width; double length;public: void setWidth(double); void setLength(double); twin getWidth() const; twin getLength() const; twin getArea() const; dual getPerimeters() const; bool isSquare() const;;#endif

1234567891011121314151617181920#include //#include "Rectangle.h"using namespace std;int main() Rectangle r; r.setWidth(3); r.setLength(5); cout "width: " "length: " "area: " "perimeters: " "Square ? " return 0;

Mar 24, 2021 in ~ 4:30am UTC
You didn"t say just how you"re compiling, but assuming g++ native the command line, you need to say something like:
(You could want -std=c++14 or also -std=c++11 instead.)Each cpp paper is compiled to a different object (.o) file. Climate the two object files are "linked" together to produce the executable. Through the above command the object papers are deleted after castle are linked into the executable, so friend won"t view them.Alternatively, you deserve to compile the cpp files to object files separately through the -c switch, then connect them in a different step. This is valuable when her program has dozens of cpp files. That way a adjust to a solitary cpp paper will only require the recompilation of one file. Then all the object files can it is in linked, i m sorry is a reasonably simple and also quick operation (mostly simply copying the files and "resolving" the references to functions and objects in the other files).

You are watching: Undefined symbols for architecture x86_64


123g++ -std=c++17 -Wall -Wextra -pedantic -c rectangle.cpp # create rectangle.og++ -std=c++17 -Wall -Wextra -pedantic -c rectangleProgram.cpp # create rectangleProgram.og++ rectangle.o rectangleProgram.o -o rectangle # creates rectangle

If you"re on windows then you most likely want to call it rectangle.exe.BTW, ns don"t understand why getPerimeters() is plural. Isn"t there just one perimeter?Also, isSquare() can be:
123456789Rectangle::Rectangle(int size) : width(size), length(size)Rectangle::Rectangle(int width_in, int length_in) : width(width_in), length(length_in)

Last edited on Mar 24, 2021 at 4:33am UTC
Mar 25, 2021 at 12:09am UTC
siid14
(35)
Perimeters must be singular (sorry).Also, i tried all your commands, none work... I"m gonna give more details. I"m making use of macOS and compile via visual Studio Code making use of the expansion Code jogger in order to compile. Maybe that details will be useful. Probably my question have to be through now, how to translate in header documents for C++ utilizing VSCode code Runner?
Mar 25, 2021 in ~ 12:37am UTC
typically you include the password (.cpp and .h, or top top mac, .cc and .h may be in use) come the project and build the project. so rectangle and rectangleprogram would BOTH encompass rectangle.h. Rectangleprogram and rectangle cpp files would BOTH be in the project. Rectangle.h may be in the task or in the encompass path (its far better if its in the job so that is indexed by the devices for simple opening and also editing). V all that, mashing develop should execute it. That looks favor you space close.
Mar 25, 2021 at 6:56pm UTC
siid14,You don"t translate into header papers separately; you #include them in the driver and also implementation, and also your compiler should immediately compile them into the executable with the others. Room you using c++ or g++ because that compiling, or room you making use of an IDE? ns would try using g++ or c++ in Terminal, and also use this format:
c++ -std=c++2a -g -o executable routine implementation

or
g++ -std=c++2a -g -o executable routine implementation

The -g flag is because that debugging, you have the right to leave that out if friend don"t should debug. The -o flag to adjust the name of the executable; if you leaving it out, that defaults to a.out.executable
is whatever you want to contact your exec,program is the surname of your driver program, favor "rectangleProgram.cpp", andimplementation is the surname of your class implementation file, favor "rectangle.cpp.dutch,Your command is backwards; it need to be:
The driver come first, climate the executable. At the very least that"s how my g++ hand-operated says to execute it. If it functions the way you do it, then you deserve to ignore what ns said.
Mar 26, 2021 in ~ 2:04am UTC
siid14
(35)
When I applied what you to speak agent max I gained the complying with error :
c++ -std=c++2a-Wall -Wextra -pedantic rectangleProgram.cpp rectangle.cpperror: invalid worth "c++2a-Wall" in "-std=c++2a-Wall"note: usage "c++98" or "c++03" because that "ISO C++ 1998 with amendments" standardnote: use "gnu++98" or "gnu++03" for "ISO C++ 1998 with amendments and also GNU extensions" standardnote: use "c++11" because that "ISO C++ 2011 through amendments" standardnote: usage "gnu++11" because that "ISO C++ 2011 through amendments and also GNU extensions" standardnote: usage "c++14" because that "ISO C++ 2014 v amendments" standardnote: usage "gnu++14" for "ISO C++ 2014 v amendments and GNU extensions" standardnote: use "c++17" because that "ISO C++ 2017 with amendments" standardnote: use "gnu++17" because that "ISO C++ 2017 with amendments and also GNU extensions" standardnote: usage "c++2a" because that "Working breeze for ISO C++ 2020" standardnote: use "gnu++2a" because that "Working draft for ISO C++ 2020 v GNU extensions" standarderror: invalid worth "c++2a-Wall" in "-std=c++2a-Wall"note: usage "c++98" or "c++03" because that "ISO C++ 1998 v amendments" standardnote: use "gnu++98" or "gnu++03" because that "ISO C++ 1998 with amendments and also GNU extensions" standardnote: usage "c++11" for "ISO C++ 2011 through amendments" standardnote: use "gnu++11" because that "ISO C++ 2011 with amendments and also GNU extensions" standardnote: use "c++14" for "ISO C++ 2014 through amendments" standardnote: usage "gnu++14" for "ISO C++ 2014 through amendments and GNU extensions" standardnote: use "c++17" for "ISO C++ 2017 v amendments" standardnote: use "gnu++17" because that "ISO C++ 2017 through amendments and GNU extensions" standardnote: use "c++2a" for "Working draft for ISO C++ 2020" standard

This is one example reason I try other command too with c++98, c++17, c++14, c++11.I made more research v the use of the extension Code runner Through the executor map (.json file) of password Runner, I have actually for c++ the complying with :"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"I expect this would aid you males to guide and make those c++ documents compile finally..

See more: 20 Best Class B Cdl Jobs Near Me Nt, Class B Cdl Driver Jobs, Employment


Last edited on Mar 26, 2021 in ~ 2:04am UTC
Mar 26, 2021 in ~ 3:10am UTC
Ganado
(6192)
-std=c++2a-Wall
These have to be two different compiler flags, separated by whitespace.-std=c++2a (enable supported C++20 features)-Wall (enable most warnings)