0

I have 3 files:

use.cpp:

#include "my.h"
int main() 
{
    foo = 7;
    print_foo();
    print(99);
}

my.cpp:

#include <iostream>
#include "my.h"
void print_foo()
{
    std::cout << foo;
}
void print(int i)
{
    std::cout << i;
}

my.h:

extern int foo;
void print_foo();
void print(int);

I get these errors when I compile and I have no idea whats wrong:

/tmp/ccYyefjH.o: In function main': use.cpp:(.text+0x6): undefined reference tofoo' /tmp/ccIgQsal.o: In function print_foo()': my.cpp:(.text+0x6): undefined reference tofoo' collect2: error: ld returned 1 exit status

I typed in

g++ -o use use.cpp my.cpp
London
  • 65
  • 3

0 Answers0