MEGAEDIT 3000
I found the reason for the undefined links. I checked the .o files for the characters and they were just missing. It just wasn’t. For no apparent reason. I checked the source of the incriminating .o file, but everything seemed to be OK. I thought this might be one of those nasty #ifdef ... #endif blocks, tricky hidden among lines of code like a bear trap, awaiting their victims. But I could not find. After moving some function definitions to the very end of the file and including them in the #ifdef ... #endif block suitable for Linux, the characters magically appeared, and everything was fine. Thank you for your time.
Out of date, do not read.
Recently, I was assigned one big project, my task is to make it work on Linux platforms. Unfortunately, the programmer who wrote the whole project in front of me did a very poor job of creating a whole batch of circular dependencies, including the B3D_Base.h file, where almost every header is #included , almost every header and source file in the project (which makes 170+ files with line #include "B3D_Base.h" ). This did not cause compilation problems on both Windows and Linux. However, this causes many 'undefined reference' errors during the Linux reference phase, although all object files and libraries are interconnected.
Meaning ld restriction of a single iteration in all object files during linking, I ask:
Is there a way to get ld to do several iterations through objects and libraries, perhaps solving all the supporting errors 700 + undefined, or is this the only chance to link the project by simply replacing all #include "B3D_Base.h" lines with proper inclusion in the necessary headers?
ANNEX No. 1:
Here is an example of what mess I have to do on Linux:
There is one header file B3D_Base.h , to which B3D_Loading3.h added, which contains the class B3D_LOADING3 . The B3D_Loading3.cpp file includes only B3D_Base.h and a memory manager class that is not included in the database. Instance B3D_LOADING3 g_Loading3; declared in B3D_Base.h and initializes +, used in many other parts of the project. Everything compiles just fine, but when it comes to links, I get a lot of 'undefined reference to g_Loading3' . And there are many more such errors, complaining about undefined references to both instances of classes and functions. So much for clean code.
ANNEX No. 2:
I will provide an SSCCE example as kfsone requested:
B3D_Base.h
... (many other includes) #include "B3D_Loading3.h" extern B3D_LOADING3 g_Loading3; ... (includes go on)
B3D_Loading3.h / B3D_Loading.cpp
a full definition of class B3D_LOADING3, but no real declaration of g_Loading3
AW_Game.cpp (one of the files that uses g_Loading3)
#include "B3D_Base.h" ... (some lines) extern B3D_LOADING3 g_Loading3;
Thanks to kfsone, which made me completely go through the code, I was able to find out what the problem is: g_Loading3 is defined everywhere as extern , therefore it is not detected properly. All I need to do is remove the extern keyword from a single file. Bugs ~ 30 links are fixed. Thanks, kfsone.
ANNEX No. 3:
But the problem with an undefined reference to class functions remains a problem. After some code scanning, I believe that the functions are not even defined due to overuse of the #ifdef ... #endif (portability), and thus this may be my mistake, ignoring functions defined only in some passive ifdef block . I will try to address this issue and then report if something changes.
APPENDIX No. 3 REPORT:
Even after the functions were correctly defined, the undefined-reference list did not decrease. Therefore, the problem remains open for discussion.
ANNEX No. 3.1
I will give an example code.
foo.h
#ifndef FOO_H #define FOO_H class Foo { unsigned int m_size; bool m_lock; friend class ASDF; public: unsigned int m_id; void Release() {delete this;} int Lock(UINT OffsetToLock, UINT SizeToLock, VOID ** ppbData, DWORD Flags); int Unlock(); };
foo.cpp
#include "Foo.h" // other includes and function definitions to follow int Foo::Lock(UINT OffsetToLock, UINT SizeToLock, VOID ** ppbData, DWORD Flags) { if(!m_lock) { // some locking code } return 0; }
Bas.cpp
#include "Foo.h"