Linkage order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

I have the following problem:

I use gcc 4.8 for compiling c++ source code - Linux and Mac platform. In
my cpp file main.cpp,
there is a function called "a" and another function called "b". In a
static library, there is a function
"c" and a function with the same name "b" as there was in the cpp file.
However, "b" in main.cpp and
in the static library have different behavior BUT the function call name
as well as the calling conventions are identical.

                  main.cpp                  
                                       Library
===============================        =========================
|--> function "a" : calls function "c"|       | --> function "c" : calls
"b"   |
|    (from library) and "b" (local)      |      |       (local)        
                     |
|--> function "b"                                 |      | --> function
"b"                    |
===============================        ==========================

The idea is that when calling "b" from within "a", it is the function
"b" which is
in main.cpp whereas when calling "b" from within "c", the function "b"
within
the library shall be called.

When linking, it seems that the symbols are linked as if all symbols are
equivalent. Hence, when in "a", "b" from the library may be called by
accident or
when in "c", function "b" may be called which is part of main,cpp. In
both cases,
this is not intended and leads to a segmentation fault.

Question: Can I somehow tell the linker to prefer "local" function calls
such that
this problem is solved? It seems that the Visual Studio linker does it
this way..

Thank you for any help.

Best regards

Hauke




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux