Linker error when using static members

后端 未结 2 1627
滥情空心
滥情空心 2020-12-11 22:06

I\'m using Qt 4.7 and Cmake 2.8.3 with g++ 4.2.1 on Mac OS X.

I\'m getting a bizarre linker error when using static or global variables in one of my files. Here\'s t

相关标签:
2条回答
  • 2020-12-11 22:24

    You need to define the static variable in cpp file and not in header file. If you define it in header file, every cpp file which includes this header will get its own copy hence linker complains about duplicate symbols.

    0 讨论(0)
  • 2020-12-11 22:44

    Static data members must be explicitly defined in exactly one compilation unit

    See this link: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

    0 讨论(0)
提交回复
热议问题