Public Group

# Link error unresolved external symbol

This topic is 4747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

------ Build started: Project: classes, Configuration: Debug Win32 ------ Linking... runmain.obj : error LNK2001: unresolved external symbol "public: static int Critter::c_number" (?c_number@Critter@@2HA) Debug/classes.exe : fatal error LNK1120: 1 unresolved externals Build log was saved at "file://c:\Documents and Settings\ASDF\My Documents\Visual Studio Projects\classes\Debug\BuildLog.htm" classes - 2 error(s), 0 warning(s) Whenever I try to compile my program, I get this error, the public: static int Critter::c_number is a string, and I included the string file. I am also using the using namespace std. My compiler is ms visual studio 2002.net

##### Share on other sites
you probably need to do define it in one of your cpp files

int Critter::c_number;

hope that helps

##### Share on other sites
Quote:
 Original post by Anonymous Posteryou probably need to do define it in one of your cpp filesint Critter::c_number;hope that helps

Also, as a note, you could even initialize it to NULL or 0 at that time:

int Critter::c_number = 0;

##### Share on other sites
true, but you don't need to - static variable storage space is automatically zeroed out in the executable when built

##### Share on other sites
didn't work, same error

##### Share on other sites
Quote:
 Original post by alyks42Linking...runmain.obj : error LNK2001: unresolved external symbol "public: static int Critter::c_number" (?c_number@Critter@@2HA)

This error is typical of a missing definition for the static member variable. As others mentioned before, you must add a definition to one (and only one) of your compilation units (usually in a .cpp file).

Quote:
 Whenever I try to compile my program, I get this error, the public: static int Critter::c_number is a string, and I included the string file.

The declaration you gave is saying that Critter::c_number is an integer, not a string. It should be defined a such.

• 10
• 17
• 9
• 14
• 41
• ### Forum Statistics

• Total Topics
631067
• Total Posts
2997740
×