【发布时间】:2013-09-30 00:33:24
【问题描述】:
我正在尝试用 Geany 编译 C++ 代码。
编译命令:g++ -Wall -c "%f"
构建命令:g++ -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" (在目录中: /home/me/projects/Test) /tmp/ccxYmWkE.o: 在函数
main': main.cpp:(.text+0x15): undefined reference toPerson::Person(int)' collect2: error: ld 返回 1 exit status 编译失败。
在 Geany 之前,我只使用 Code::Blocks 并且一切正常。我该如何解决?
【问题讨论】:
-
您可以(并且可能应该)配置 Geany 为 GNU 使用
Makefilemake;您的构建命令显然是错误的,您需要链接几个目标文件...
标签: c++ compiler-construction reference undefined geany