I have two libraries , named ( lib1 and lib2) , both are not dependent on each other. I do not have control over how these libraries are built. When I try to link them the order of linking dictates on different behaviors within the final executable,
For example:
If I link them as [1]
gcc $(CC_FLAGS) -o app.out -llib1 -llib2
everything works fine
But, if I link them as following [2]
gcc $(CC_FLAGS) -o app.out -llib2 -llib1
A segmentation fault occurs during executable run.
Any advice or pointer on the cause of this problem would be helpful.
Update:
Both of these libraries are dependent on another dynamic library, which is Apache Thrift ( Version 0.11.0) the segfault occurs on lib1 if it is compiled [1] option above, and exception occurs on lib2 if it compiled with option [2] above.
Update 2
The issue is due to global namespace violations between the libraries. Since thrift uses IDL mechanism to generate source files, Both libraries ( somehow ) defined the same namespace for their IDL definitions, hence such behavior was observed. Accepting the answer below as correct one since it addresses the question indirectly.
Thank you.