Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use cmake or link an example? #175

Closed
marbx opened this issue Jan 1, 2024 · 5 comments
Closed

How to use cmake or link an example? #175

marbx opened this issue Jan 1, 2024 · 5 comments

Comments

@marbx
Copy link

marbx commented Jan 1, 2024

Hello,
because the Debian 12 Boost package libboost-all-dev does not include Redis, I "bootstrapped" boost 1.84.0 with

mkdir -p /home/marbx/boost/install
./bootstrap.sh --prefix=/home/marbx/boost/install
./b2 install

I can compile and run a Boost coroutine example using

g++ -Wl,--verbose=99 -std=c++20  example.cpp\
    -I/home/marbx/boost/install/include\
    -L/home/marbx/boost/install/lib\
    -lboost_coroutine -lboost_context -lboost_system -lm -lxml2 -lssl -lcrypto

export LD_LIBRARY_PATH=/home/marbx/boost/install/lib

./a.out

When I try to run cmake, as described in the README,...

BOOST_ROOT=/home/marbx/boost/install    cmake --preset g++-11

... I get many errors:

CMake Error at CMakeLists.txt:83 (add_subdirectory):
  add_subdirectory given source "../system" which is not an existing
  directory.
CMake Error at CMakeLists.txt:83 (add_subdirectory):
  add_subdirectory given source "../assert" which is not an existing
  directory.
...snip...
-- Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
-- Configuring incomplete, errors occurred!

When I try to compile the Redis cpp17_intro example using...

g++ -Wl,--verbose=99 -std=c++17 example/cpp17_intro.cpp\
    -I/home/marbx/boost/install/include\
    -L/home/marbx/boost/install/lib\
    -lboost_thread -lssl -lcrypto -lm -lxml2 -lboost_coroutine -lboost_context -lboost_system

... I get many linker errors:

undefined reference to `boost::redis::connection::connection(boost::asio::io_context&, boost::asio::ssl::context_base::method, unsigned long)'
undefined reference to `boost::redis::connection::cancel(boost::redis::operation)'
...snip...
undefined reference to `boost::redis::resp3::boost_redis_to_bulk
collect2: error: ld returned 1 exit status

It seems I must specify a library, but there is no library called *redis* under /home/marbx/boost/install/lib/

What am I missing?
Thanks

P.S.
I corrected the g++ calls because they formerly used libraries from /usr/lib/*

@marbx
Copy link
Author

marbx commented Jan 1, 2024

cancel is defined in connection.hpp, a header only file. There is no need for a library.
The problem is that connection.hpp is not read, so the linker must assume it is in a library.

g++ -H shows that compiler reads 5 redis related files, namely:

/home/marbx/boost/install/include/boost/redis/logger.hpp
/home/marbx/boost/install/include/boost/redis/detail/connector.hpp
/home/marbx/boost/install/include/boost/redis/detail/resolver.hpp
/home/marbx/boost/install/include/boost/redis/detail/handshaker.hpp
/home/marbx/boost/install/include/boost/redis/usage.hpp

So the question is why the compiler does not read

/home/marbx/boost/install/include/boost/redis/connection.hpp 

File permissions are regular

@mzimbres
Copy link
Collaborator

mzimbres commented Jan 1, 2024

Hi, there are some problems building with cmake in the master branch. I have made some fixes in the develop though. This should work

# Clone the superproject (perhaps using shallow copies)
$ git clone --recurse-submodules https://github.com/boostorg/boost

# Checkout the develop branch
$ git submodule foreach --recursive git checkout develop

# Do an out of source build
$ mkir build
$ cmake ../boostorg/libs/redis
$ cmake --build . --target cpp20_intro

Let me know if this works for you.

@mzimbres
Copy link
Collaborator

mzimbres commented Jan 1, 2024

cancel is defined in connection.hpp, a header only file. There is no need for a library.
The problem is that connection.hpp is not read, so the linker must assume it is in a library.

You need to build the library yourself by including #include <boost/redis/src.hpp> in one cpp file, it can be the one where you define the main function.

@marbx
Copy link
Author

marbx commented Jan 1, 2024

Adding #include <boost/redis/src.hpp> to example/cpp17_intro.cpp results in 0 errors and a nice and cozy PING: Hello world :-)

Excellent!

Thank you a lot. Looking forward to continue from here, and to look into cloning the superproject, too.

Closing the issue, because the README already contains the advise. I just overlooked it.

@marbx marbx closed this as completed Jan 1, 2024
@marbx
Copy link
Author

marbx commented Jan 2, 2024

Hi, there are some problems building with cmake in the master branch. I have made some fixes in the develop though. This should work

# Clone the superproject (perhaps using shallow copies)
$ git clone --recurse-submodules https://github.com/boostorg/boost

# Checkout the develop branch
$ git submodule foreach --recursive git checkout develop

# Do an out of source build
$ mkir build
$ cmake ../boostorg/libs/redis
$ cmake --build . --target cpp20_intro

Let me know if this works for you.

@mzimbres , yes, this worked out fine and I executed

$ example/cpp20_intro 
PING: Hello world

I like this out-of-source-build path, I now only have to better understand cmake :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants