我想与Geany编译C++代码。Geany - 未定义的参考
编译命令:克++ -Wall -c “%F”
生成命令:克++ -Wall -o “%e” 的 “%F”
main.cpp中:
#include <iostream>
#include "Person.hpp"
int main()
{
Person p1(16);
std::cout << p1.getAge();
return 0;
}
Person.hpp
class Person
{
public:
Person(int a);
void setAge(int);
int getAge() const;
private:
int age;
};
inline int Person::getAge() const
{
return age;
}
Person.cpp
#include "Person.hpp"
Person::Person(int a)
{
age = a;
}
void Person::setAge(int a)
{
age = a;
}
错误:
g++ -Wall -o "main" "main.cpp" (in directory: /home/me/projects/Test) /tmp/ccxYmWkE.o: In function
main': main.cpp:(.text+0x15): undefined reference to
Person::Person(int)' collect2: error: ld returned 1 exit status Compilation failed.
Geany之前,我只用代码::块和一切工作正常。我该如何解决它?
可以(并且可能应该)配置* Geany *使用'Makefile'用于GNU [制造](http://www.gnu.org /软件/制造/);你的build命令显然是错误的,你需要链接几个目标文件... –