"неопределенная ссылка" Ошибка при запуске простой программы на C++
Этот main.cpp печатает цену на Dishes: у нас есть заголовок и файл cpp, каждый в своей отдельной папке include, для заголовка и папки src, для файла cpp.
#include <iostream>
#include "../include/Dish.h"
int main() {
Dish *d1 = new Dish(0,"Beer",10,ALC);
Dish *d2 = new Dish(1,"Curry",50,SPC);
std::cout << d1->getPrice() << std::endl;
}
это наш Dish.h:
#ifndef DISH_H_
#define DISH_H_
#include <string>
enum DishType{
VEG, SPC, BVG, ALC
};
class Dish{
public:
Dish(int d_id, std::string d_name, int d_price, DishType d_type);
int getId() const;
std::string getName() const;
int getPrice() const;
DishType getType() const;
private:
const int id;
const std::string name;
const int price;
const DishType type;
};
и наш Dish.cpp:
#include "../include/Dish.h"
#include <iostream>
//--------Constructor---------//
Dish(int d_id, std::string d_name, int d_price, DishType d_type):id(d_id),name(d_name),price(d_price),type(d_type){}
//----------Methods-----------//
int Dish::getId() const{
return id;
}
std::string Dish::getName() const{
return name;
}
int Dish::getPrice() const{
return price;
}
DishType Dish::getType() const{
return type;
}
по какой-то причине мы получаем эту ошибку:
/users/studs/bsc/2019/vardidan/clion-2018.2.5/bin/cmake/linux/bin/cmake --build /users/studs/bsc/2019/vardidan/CLionProjects/untitled/cmake-build-debug --target untitled -- -j 2
[ 50%] Linking CXX executable untitled
CMakeFiles/untitled.dir/src/main.cpp.o: In function `main':
/users/studs/bsc/2019/vardidan/CLionProjects/untitled/src/main.cpp:5: undefined reference to `Dish::Dish(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, DishType)'
/users/studs/bsc/2019/vardidan/CLionProjects/untitled/src/main.cpp:6: undefined reference to `Dish::Dish(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, DishType)'
/users/studs/bsc/2019/vardidan/CLionProjects/untitled/src/main.cpp:8: undefined reference to `Dish::getPrice() const'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled.dir/build.make:83: recipe for target 'untitled' failed
make[3]: *** [untitled] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/untitled.dir/all' failed
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/untitled.dir/rule' failed
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
Makefile:118: recipe for target 'untitled' failed
make: *** [untitled] Error 2
Если Clion делает для нас make-файл, почему существует проблема с make-файлом?