c++ - 错误 : undefined reference to `censorship()'

标签 c++ reference undefined

<分区>

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

我有main.cpp:

#include "censorship_dec.h"

using namespace std;

int main () {
    censorship();
    return 0;
}

这是我的censorship_dec.h:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

void censorship();

这是我的censorship_mng.cpp:

#include "censorship_dec.h"
using namespace std;

void censorship()
{
   cout << "bla bla bla" << endl;
}

我试图在 SSH (Linux) 中运行这些文件,所以我写了:make main,但我得到了:

g++     main.cpp   -o main
/tmp/ccULJJMO.o: In function `main':
main.cpp:(.text+0x71): undefined reference to `censorship()'
collect2: ld returned 1 exit status
make: *** [main] Error 1

请帮忙!

最佳答案

您必须指定定义censorship 的文件。

g++ main.cpp censorship_mng.cpp -o main

关于c++ - 错误 : undefined reference to `censorship()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14336852/

相关文章:

c++ - 编译器会优化掉未使用的链接文件吗?

JavaScript异步函数Google Sheet API,数据可用性因公式检索而延迟?如何克服?

c++ - 近正弦数据下界的(线性或多项式)回归算法

c++ - 使用 Boost 同时记录到控制台和文件

c# - 确定项目对 mscorlib 的引用

java - 检测对象是否存储状态或是否可以共享

.net - Visual Studio 引用管理器 - 程序集框架与 COM 类型库

javascript - 设置 leaflet.js map 显示当前位置

javascript - Uncaught ReferenceError : Backbone is not defined

.net - 使 .net 框架兼容