https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61549

            Bug ID: 61549
           Summary: Error when linking with shared libraries
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: isak50 at mail dot ru

// os - linux debian

//------ /usr/local/lib/1.cpp
#include <iostream>
struct S
{
    int val;
    S() {val=1; std::cout << "1::constr\n";}
    ~S() {std::cout << "1::destr\n";}
}s;
extern int f1() {return s.val;}

//------ /usr/local/lib/2.cpp
#include <iostream>
struct S
{
    int val;
    S() {val=2; std::cout << "2::constr\n";}
    ~S() {std::cout << "2::destr\n";}
}s;
extern int f2() {return s.val;}

//------ /usr/local/lib/ex.cpp
#include <iostream>
extern int f1();
extern int f2();
int main()
{
    std::cout << "ex::main\n";
    std::cout << "f1 = " << f1() << "\n";
    std::cout << "f2 = " << f2() << "\n";
    return 0;
}

//------ buid
/usr/local/lib $ g++ 1.cpp -fPIC -shared -o lib1.so
/usr/local/lib $ g++ 2.cpp -fPIC -shared -o lib2.so
/usr/local/lib $ g++ ex.cpp lib1.so lib2.so -o ex
/usr/local/lib $ ldconfig

//------ run
./ex

//------ output
1::constr
1::constr   // Why 1::constr? should be 2::constr
ex::main
f1 = 1
f2 = 1
1::destr    // Why 1::destr? should be 2::destr
1::destr

Reply via email to