Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对“addVectors(Vector,Vector)”的未定义引用_C_Codeblocks_Glut - Fatal编程技术网

对“addVectors(Vector,Vector)”的未定义引用

对“addVectors(Vector,Vector)”的未定义引用,c,codeblocks,glut,C,Codeblocks,Glut,我无法解决这些未定义的参考问题。我的头文件中可能有错误。我的IDE是代码块 #include<windows.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif #include <stdio.h> #include <stdlib.h> #include "maths.h" #include <math.h> int

我无法解决这些未定义的参考问题。我的头文件中可能有错误。我的IDE是代码块

#include<windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

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

#include "maths.h"
#include <math.h>

int main(int argc, char *argv[])
{
    //stuff
    struct Vector v1;
    struct Vector v2;

    v1.x = 3;
    v1.y = 4;

    v2.x = 6;
    v2.y = 10;



    struct Vector v3 = addVectors(v1,v2);

    printf("%f %f",v3.x,v3.y);

}

尝试这样更改函数:

struct Vector* addVectors(struct Vector v1, struct Vector v2);

在这个函数中,返回一个向量指针

,你似乎不是用包含addVectors函数的源文件构建的。同意一些程序员的说法。您从链接器ld收到一个错误,这意味着它不是包含问题。您还没有告诉IDE构建math.c文件并将其链接到项目中。为什么?这将如何解决OP询问的构建错误?@mm98这肯定不是正确的答案。无论如何,这是一个链接器错误,而不是编译错误。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "maths.h"

void setVector(struct Vector *v, float x, float y){

    v->x = x;
    v->y = y;

}

struct Vector addVectors(struct Vector v1, struct Vector v2){

    int x1 = v1.x;
    int x2 = v2.x;
    int y1 = v1.y;
    int y2 = v2.y;

    struct Vector v3;

    v3.x = x1 + x2;
    v3.y = y1 + y2;

    return v3;

}

 void makeUnit(Vector *v){

    double a = (v->x * v->x) + (v->y * v->y);
    double lengthvector = sqrt(a);

    v->x = x/lengthvector;
    v->y = y/lengthvector;

}
||=== Build: |192|undefined reference to `addVectors(Vector, Vector)'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
struct Vector* addVectors(struct Vector v1, struct Vector v2);