1

When I compile the below program it is giving me this error.

/tmp/ccwr6gsJ.o: In function 'main':
main.cL(.text+0xa): undefined reference to 'example'
collect2: error: Id returned 1 exit status

Main.c:

#include <stdio.h>

#include "includes.h"

int main()
{
    int exampleInt = example();

    return 0;
}

includes.h:

int example();

includes.c:

#include "includes.h"

int example()
{
    int i = 3;

    return i;
}

It seems to work in Visual Studio but not on GCC on Linux

1 Answer 1

6

This is very likely a build error, i.e. you're calling the compiler on the wrong set(s) of files, and/or not doing a linking step.

Try:

$ gcc -o myprog main.c example.c

Note that a mere #include in a C file does not in any way tell the compiler to compile more C files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.