public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/61549] New: Error when linking with shared libraries
@ 2014-06-18 10:35 isak50 at mail dot ru
2014-06-18 11:17 ` [Bug other/61549] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: isak50 at mail dot ru @ 2014-06-18 10:35 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug other/61549] Error when linking with shared libraries
2014-06-18 10:35 [Bug other/61549] New: Error when linking with shared libraries isak50 at mail dot ru
@ 2014-06-18 11:17 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-06-18 11:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61549
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
You are violating the one-definition-rule (ODR) of C++. It's undefined if
two same classes have different implementations.
Put them in anonymous namespaces and it'll work.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-18 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-18 10:35 [Bug other/61549] New: Error when linking with shared libraries isak50 at mail dot ru
2014-06-18 11:17 ` [Bug other/61549] " rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).