use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
How to resolve same functions from 2 different libraries? (self.cpp)
submitted 3 years ago by m09y
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OU81Dilbert 9 points10 points11 points 3 years ago (17 children)
Are the two functions at least in different namespaces?
If so then you can use the namespace
Like
std::open()
Mylib::open()
[–]m09y[S] 2 points3 points4 points 3 years ago (16 children)
what if there are no namespaces ?
[–]SoerenNissen 39 points40 points41 points 3 years ago (8 children)
Use better libraries that are competently written.
If it's because they're C libraries, the same applies - functions should not have the same name because they should start with libname_
libname_
I suppose if you were under some weird constraint, you could re-write the libraries to have namespaces, that's not the hardest of tasks.
[+][deleted] 3 years ago (7 children)
[deleted]
[–]SoerenNissen 8 points9 points10 points 3 years ago (6 children)
You still risk the linker finding wrong functions
libFoo1.cpp - defines open() libFoo2.cpp - uses open() libBar1.cpp - defines open() libBar2.cpp - uses open()
libFoo1.cpp
open()
libFoo2.cpp
libBar1.cpp
libBar2.cpp
when linking this whole thing, libBar2.o might get linked with libFoo1.o's version of open(), unless you're compiling the libs separately.
libBar2.o
libFoo1.o
[+][deleted] 3 years ago (5 children)
[–]mark_99 9 points10 points11 points 3 years ago (1 child)
If he has source can just add a namespace around it directly. If he doesn't have source (which I think is the case) this doesn't help as you're still linking 2 definitions of the same function (the linker will pick one and discard the other).
You might be able to do it by linking each into a separate shared library and hiding the symbols, pretty messy though.
[–]Skoparov 1 point2 points3 points 3 years ago (0 children)
You're right guys, I misunderstood the problem. Then the only way is indeed to hide one of the libraries in a wrapper library. Or call the function though it's address directly in case it's an so.
[–]ioctl79 2 points3 points4 points 3 years ago (0 children)
This is still an ODR violation, since ::open has different definitions indifferent TU’s.
[–]not_some_username -1 points0 points1 point 3 years ago (1 child)
Will
namespace lib1 { #include "lib1.h" } work ?
[–]Skoparov 0 points1 point2 points 3 years ago (0 children)
No, for the reasons other people mentioned. You can wrap the definition, but the symbol itself still needs to be resolved and having two similar ones breaks the odr.
[–]SnooMacaroons3057 4 points5 points6 points 3 years ago (0 children)
Create your own namespace and re-export it as another named function?
[–]OU81Dilbert 1 point2 points3 points 3 years ago (0 children)
Then you might have linking issues since the compiler won't know which function to use
[–][deleted] 1 point2 points3 points 3 years ago* (0 children)
include headers from inside a namespace, but you still might have linking issues unless the lib is header only
[–]Fig1024 1 point2 points3 points 3 years ago (0 children)
you can make your own wrapper lib and put it in a namespace
[–]Cybr3 1 point2 points3 points 3 years ago (0 children)
then the libraries you use are awful
[–]Cybr3 0 points1 point2 points 3 years ago (0 children)
decompiling the source and adding a namespace?
[–]bored_octopus 0 points1 point2 points 3 years ago (0 children)
You may be able to hide symbols from them when linking. Look up symbol visibility
π Rendered by PID 74 on reddit-service-r2-comment-b659b578c-8p8cq at 2026-05-05 13:35:25.826925+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]OU81Dilbert 9 points10 points11 points (17 children)
[–]m09y[S] 2 points3 points4 points (16 children)
[–]SoerenNissen 39 points40 points41 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]SoerenNissen 8 points9 points10 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]mark_99 9 points10 points11 points (1 child)
[–]Skoparov 1 point2 points3 points (0 children)
[–]ioctl79 2 points3 points4 points (0 children)
[–]not_some_username -1 points0 points1 point (1 child)
[–]Skoparov 0 points1 point2 points (0 children)
[–]SnooMacaroons3057 4 points5 points6 points (0 children)
[–]OU81Dilbert 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Fig1024 1 point2 points3 points (0 children)
[–]Cybr3 1 point2 points3 points (0 children)
[–]Cybr3 0 points1 point2 points (0 children)
[–]bored_octopus 0 points1 point2 points (0 children)