[vtkusers] Cannot use 'extern' keyword in a project made by Cmake?
Brad King
brad.king at kitware.com
Tue Apr 10 11:44:47 EDT 2007
Janny Dong wrote:
> I have been learning how to use VTK with MFC in my visualization
> project. VS 2005 is installed on my machine. I succeeded in building all
> VTK files and running some examples. When I generated my own project
> with Cmake, I couldn’t build it. I declared several variables in my
> header file using the keyword ‘extern’. For example, ‘extern int year,
> month, day’. In the building process, I kept getting errors like
>
> ‘error LNK2001: unresolved external symbol “int year” (?year@@3HA)’
>
> When I deleted the word ‘extern’, my project got built. Anyone has any
> thoughts? Thanks in advance.
This has nothing to do with VTK or CMake. The "extern" keyword tells
the compiler that the variables you declare are defined somewhere else.
If no .cxx file actually contains the definitions then the linker
complains. By removing the "extern" keyword you are causing every .cxx
file that includes the header to get its own copy of the global variable
definition. This is usually not what you want.
-Brad
More information about the vtkusers
mailing list