Search code examples
cgccmodular-design

Error compiling modular code in VSC using gcc


I've a problem compiling the following programm:

// hauptteil.c (main part)
#include "nebenfkt.h"
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int x =10;
    int ergebnis=0;
    ergebnis =ver(x);
    printf("Doubled number: %d", ergebnis);
    return 0;
}
//nebenfkt.h
int ver(int x);
#include "nebenfkt.h"
#include <stdio.h>
#include <stdlib.h>


int ver(int x)
{
    int rueck;
    rueck= x*2;
    return rueck;
}

VSC gives me the feedback "* undefined reference to `ver' collect2.exe: error: ld returned 1 exit status*"

Solution

The problem occurred because I only used the command "gcc hauptteil.c -o function" Instead of "gcc hauptteil.c nebenfkt.c -o function"


Solution

  • My mistake was discovered by Eugene Sh.

    My mistake was that I only used the command "gcc hauptteil.c -o function" Instead of "gcc hauptteil.c nebenfkt.c -o function".