chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.96k stars 1.22k forks source link

Boost and non-Boost asio conflicts when used in one project #874

Open giesmininkas opened 3 years ago

giesmininkas commented 3 years ago

Hi.

When trying to use both Boost and non-Boost versions of asio, it fails to compile with multitude of target of using declaration conflicts with declaration already in scope and redefinition of '*' errors. I checked it with Boost 1.74.0 and asio >=1.18.0.

I was hoping this would work, since asio documentation says "Can Asio and Boost.Asio coexist in the same program? Yes. Since they use different namespaces there should be no conflicts, although obviously the types themselves are not interchangeable."

Is this an expected behaviour? Could someone suggest a workaround to be able to use both versions together?

Steps to recreate:

git clone -b asio-1-18-0 https://github.com/chriskohlhoff/asio.git

cat > main.cpp <<EOF
#include "asio.hpp"
#include <boost/asio.hpp>
int main() {}
EOF

clang++ -std=c++11 -I asio/asio/include main.cpp
g++ -std=c++11 -I asio/asio/include main.cpp

Thank you in advance.

Smadas commented 3 years ago

Maybe obvious but, Ill try. Didnt you by any chance use "using namespace", effectively disabling the different namespaces?

giesmininkas commented 3 years ago

Maybe obvious but, Ill try. Didnt you by any chance use "using namespace", effectively disabling the different namespaces?

HI. No, I did not use "using namespace". The errors occur in the example posted above. It's enough to just "include" both asio flavors.

tstenner commented 3 years ago

"Can Asio and Boost.Asio coexist in the same program? Yes. Since they use different namespaces there should be no conflicts, although obviously the types themselves are not interchangeable."

This means that you can use Boost.Asio in separate compilation units and link them together, but you can't rely on importing them into the same compilation unit.

terrakuh commented 1 year ago

I thought everything for Boost.ASIO is put in its own namespace? With this issue it's not possible to include ASIO and for example Boost.Process in one translation unit because the latter one includes Boost.ASIO.