虽然有一些同名的问题,但我相信我的问题没什么不同。
我有3个文件:main.cpp,car.h和car.cpp。
main.cpp中:
#include <string>
#include <iostream>
#include "car.h"
int main(int argc, const char * argv[]) {
Car v;
std::cout << v.getName() << std::endl;
return 0;
};
car.h
#include <string>
#include <iostream>
#ifndef CAR_H
#define CAR_H
class Car {
public:
std::string getName();
};
#endif // MAINWINDOW_H
car.cpp
#include "car.h"
std::string Car::getName() {
return "blah";
};
当我使用&#34; g ++ main.cpp&#34;在终端中运行时,我收到了这条奇怪的消息:
Undefined symbols for architecture x86_64:
"Car::getName()", referenced from:
_main in main-b1d04e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
这是一个新手问题,但有人可以帮助我吗?