Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
IDE: C++ Builder 6.0
Project type: Console
[Linker Fatal Error] Fatal: Oject file MyFile.OBJ is missing a section of class 2
This error occurs when:
Download a C++ Builder project with this error.
There are more.
Restructure the program so you will not need to use globals. If this fails, use the Singleton Design Pattern.
Go to 'Project | Options | Compiler | Pre-compiled headers' and select 'None'. Your error message will change to the following warning:
[Linker Warning] Public symbol '_x' defined in both module MyUnit1.OBJ and MyUnit2.OBJ
[Linker Warning] Public symbol '_x' defined in both module MyUnit1.OBJ and MyUnit3.OBJ
This solution is not recommended, because one should using global data [0] [1] [2] [3] [4] , especially in the global namespace [5] .
Suppose you have declared an integer called 'x' in a header file (.h) like below:
int x;
Put it into a namespace called 'global' like below:
namespace global
{
int x;
}
Your error message will change to the following warning:
[Linker Warning] Public symbol 'global::x' defined in both module MyUnit1.OBJ and MyUnit2.OBJ
[Linker Warning] Public symbol 'global::x' defined in both module MyUnit1.OBJ and MyUnit3.OBJ
This solution is not recommended, because one should using global data [0] [1] [2] [3] [4] .
Suppose you have declared an integer called 'x' in a header file (.h) like below:
int x;
Make it static like below:
This solution is not recommended, because one should using global data [0] [1] [2] [3] [4] , especially in the global namespace [5] .
[0] Herb Sutter , Andrei Alexandrescu . C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 10: 'Minimize global and shared data'.
[1] Herb Sutter , Andrei Alexandrescu . C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 18: 'Declare variables as locally as possible'.
[2] Bjarne Stroustrup . The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4. Chapter 1.8.2.a: 'Don't use global data (use members)'
[3] Jarrod Hollingworth , Bob Swart, Mark Cashman, Paul Gustavson. Sams C++ Builder 6 Developer's Guide. ISBN: 0-672-32480-6. Chapter 3: 'Avoid using global variables'
[4] Jesse Liberty . Sams teach yourself C++ in 24 hours. ISBN: 0-672-32224-2. Hour 5, paragraph 'Global variables': 'In C++, global variables are avoided because they can create very confusing code that is hard to maintain.'
[5] Bjarne Stroustrup . The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4. Chapter C.14.15: 'Don't pollute the global namespace'.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.