这个问题并不新鲜,但老实说我不知道我做错了什么。该程序应该采用一个表达式,对其进行修改,调用一些汇编代码,然后显示结果,但不知何故,在包含包含所需分析函数的 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/