C"未定义参考"导致多源项目的构建失败

时间:2015-09-15 22:34:05

标签: c build linker codeblocks

我正在尝试从下面的源文件构建并运行可执行文件,但在无忧无虑的编译之后,我在构建时不断收到以下消息:

undefined reference to 'lessThanFunction'
undefined reference to 'moreThanFunction'

我无法理解我的功能是如何定义的。我被告知它是链接器错误,但新项目文件夹和文件中的相同代码会产生相同的错误。我想我需要编辑.cbp文件以识别.o文件,但我不确定如何。

main.c中

#include <stdio.h>
#include <stdlib.h>
#include "functions.h"

int main()
{
    /* variable declarations */
    int x;
    int y;
    int z;

    /* main function */
    printf("Enter two integer values, separated by a single space.  If the sum of the two values = 100 or more, the program will return HELLO.\n  If the sum of the two values = less than 100, the program will return GOODBYE.");
    scanf("%i %i", &x, &y);

    z = x + y;

    if(z > 100)
    {
        moreThanFunction(x, y, z);
    }

    if(z <= 100)
    {
        lessThanFunction(x, y, z);
    }
return 0;
}

functions.h

#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

/* function declarations */
void moreThanFunction(int x, int y, int z);
void lessThanFunction(int x, int y, int z);

#endif // FUNCTIONS_H_INCLUDED

functions.c

#include "functions.h"

/* function definitions */
void moreThanFunction(int x, int y, int z)
{
    printf("%i + %i = %i    Hello, world!", x, y, z);
}

void lessThanFunction(int x, int y, int z)
{
    printf("%i + %i = %i    Goodbye, world.", x, y, z);
}

0 个答案:

没有答案
相关问题