0

I give an example very close to my code:

camera.h

#pragma once

#ifndef VCL_CAMERA_TRACKING_H
#define VCL_CAMERA_TRACKING_H

extern int x;
....
#endif

main.cpp

#include "camera.h"
...    
int x = 15;

b.cpp

#include "camera.h"
...
int example = 15;
int numFaces = 0;
...
if(numFaces<1) x = example;
...

when I build my project in VS10 I get "error LNK2001: unresolved external symbol "int x" (?x@@3HA) at b.cpp".

It is strange because I have declared x in camera.h and defined it at main.cpp

lestreinz
  • 36
  • 4
  • See this answer - http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574403#12574403 – Luchian Grigore Feb 06 '15 at 10:18
  • Also see https://stackoverflow.com/questions/10585421/global-variable-declaration-with-extern – sashoalm Feb 06 '15 at 10:18

1 Answers1

1

You have declared your symbol:

extern int x;

But you haven't defined your symbol anywhere. You need to put

int x;

In one of your source files.

sjdowling
  • 2,994
  • 2
  • 21
  • 31
  • I think VS started to melt down. I defined x in b.cpp instead of main.cpp and it seems ok. thnx though! – lestreinz Feb 06 '15 at 10:32