error when compiling - linking .cpp & header file

后端 未结 2 1926
旧时难觅i
旧时难觅i 2021-01-23 08:32

I\'m attempting to link my .cpp implementation file with my header file - I get this error message from my mac terminal -

rowlandev:playground rowlandev$ g++ ma         


        
2条回答
  •  离开以前
    2021-01-23 09:17

    Here's a good read to understand what's going on when you try to create an executable from source code: How does the compilation/linking process work?

    What's going on here is that the linker doesn't know where Person::Person(), which is being called in main(), is located. Notice how when you called g++, you never gave it the file where you wrote code for Person::Person().

    The right way to call g++ is: $ g++ -o main main.cpp person.cpp

提交回复
热议问题