c++ - undefined reference ...被引用的东西

标签 c++ codeblocks undefined-reference

这个问题并不新鲜,但老实说我不知道​​我做错了什么。该程序应该采用一个表达式,对其进行修改,调用一些汇编代码,然后显示结果,但不知何故,在包含包含所需分析函数的 analyse.h 文件之后,main 似乎无法访问所述函数。

除了编写#include "analyse.h",我还应该做什么?

(另外,“Analyse”部分不是我的,无法修改,只能修改main。)

提前致谢!

错误:

undefined reference to `shuntingYard(char*, char*, int)'
undefined reference to `makeTree(char*)'
undefined reference to `deleteTree(Noeud*)'

主要内容:

#include <iostream>

#include "analyse.h"

using namespace std;

int main()
{
    char entry[500];
    char* pEntry = entry;
    char polonaise[1000];
    char* pPolonaise = polonaise;
Noeud* root;

string rawEntry;

//read expression

cin >> rawEntry;

for(size_t i = 0; i < rawEntry.size() ; i++)
    entry[i] = rawEntry[i];

//convert tree

shuntingYard(pEntry, pPolonaise, rawEntry.size());

root = makeTry(pPolonaise);

//* ... */

deleteTry(root);

return 0;

}

分析.h:

#ifndef ANALYSE_H
#define ANALYSE_H

#include <stdio.h>
#include <string.h>
#include <stack>

#define TYPE_NOMBRE 0
#define TYPE_OPERATEUR 1
#define TYPE_VARIABLE 2

using namespace std;

struct Noeud
{
 int type;
 int valeur;
 Noeud* gauche;
 Noeud* droite; 
};
/* ... */
void shuntingYard(char *,char*, int);

/* ... */
Noeud* makeTree(char *);

/* ... */
void deleteTree(Noeud*);

#endif

最佳答案

您需要链接包含实现的代码(或库)。

如果您获得了实现的源代码 (analyse.cpp),那么您可以将其编译并链接到您的可执行文件中。

如果您获得了用于实现的共享对象/dll,那么您将需要链接到 .so/.lib。

如果您获得了一个静态库,那么您将需要链接到 .a/.lib。

关于c++ - undefined reference ...被引用的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22697181/

相关文章:

C++概念不好用?

c++ - 如何从 makefile 在 Linux 上安装程序?

c++ - 代码块编译后需要很长时间才能执行

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

c++ - 构造后更改指针的地址

c++ - 在 C++11 中实现 copy-and-swap 习惯用法的更好方法

c - 为什么要使用递归来求一个数的阶乘?

C++ 发布 exe 不工作代码块

c++ - 命令行中缺少 DSO

c++ - 为什么尝试在类中设置静态变量时出现链接器错误?