未定义的变量错误 [英] Undefined Variable error

查看:179
本文介绍了未定义的变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,在C语言编程,而我无法理解的是未来,当我试图编译我的程序错误。我有下面的程序,这是相当简单和我的教授说是正确的:

I'm a newbie to programming in C, and I'm having trouble understanding the error that is coming up when I attempt to compile my program. I've got the following program, which is fairly simple and which my professor says is correct:

#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define BOOL int

extern int x;
extern BOOL do_exp;
int exp_or_log();

main()
{
   x = 10;
   do_exp = TRUE;
   printf("2^%d = %d\n", x, exp_or_log());  //should print 1024

   x = 145;
   do_exp = FALSE;
   printf("log(%d) = %d\n", x, exp_or_log());  //should print 7
}

但是当我尝试编译它,我得到:

But when I try to compile it, I get:

  "_x", referenced from:
      _x$non_lazy_ptr in ccWdLlxk.o
  "_exp_or_log", referenced from:
      _main in ccWdLlxk.o
      _main in ccWdLlxk.o
  "_do_exp", referenced from:
      _do_exp$non_lazy_ptr in ccWdLlxk.o
ld: symbol(s) not found

我甚至不足够的这是什么意思知道从哪里开始试图找出此问题的想法。如果任何人有一个有用的解释,还是应该看什么,我在开始拍摄问题,哪怕只是一个总的想法,我真的AP preciate它。

I don't even have enough of an idea of what that means to know where to begin trying to figure out the problem. If anyone has a helpful explanation, or even just a general idea of what I should look at to begin problem shooting, I'd really appreciate it.

推荐答案

X do_exp exp_or_log()都在另一个文件中定义的,我猜你的教授提供。您需要与该文件链接在一起。这通常是通过与您的编译行你一起把它的文件名完成的。

x, do_exp, and exp_or_log() are all defined in another file, I'm guessing supplied by your professor. You need to link together with that file. This is usually done by adding its filename along with yours on your compile line.

这篇关于未定义的变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆