Boost lib and build from source - Dieptranivsr/DroneIVSR GitHub Wiki

In CMake, PUBLIC (for everyone) = INTERFACE (for the other) + PRIVATE (for me)

Rule of thumb for visibility settings

When working out which visibility settings to use for the properties of your targets you can refer to the following table:

Who need ? Long Cell
Target YES NO
YES PUBLIC PRIVATE
NO INTERFACE N/A

The internal dependency tree

You can visualize the dependencies between the targets in your project with Graphviz:

$ cd build
$ cmake --graphviz=project.dot ..
$ dot -T svg project.dot -o project.svg

image

The dependencies between targets in the cellular automata project.

Go to page. Link https://www.boost.org/users/history/version_1_82_0.html

dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev$ wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.bz2
dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev$ tar --bzip2 -xf boost_1_82_0.tar.bz2
dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev$ cd boost_1_82_0/
dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev/boost_1_82_0$ ./bootstrap.sh
dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev/boost_1_82_0$ sudo ./b2 install --prefix=/usr/local/
dieptt@DESKTOP-BF5GK0T:~/Libs/boost-dev/boost_1_82_0$ cat /usr/local/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_82"
dieptt@DESKTOP-BF5GK0T:~/Libs/testLibs/testBoostLibs$ tree -L 4
.
├── CMakeLists.txt
├── boost_ex.cpp
├── boost_filesystem.cpp
└── boost_thread.cpp

boost_ex.cpp

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

int main()
{
    long long num1 = 1523844560192817464;
    long long num2= 598274671729184766;
    int128_t result = (int128_t) num1 * num2;
    std::cout << "The product of the two integers is:" << "\n" << result << std::endl;
    return 0;
}

boost_filesystem.cpp

#include <iostream>
#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;

int main() {
    // Get the current working directory
    fs::path cwd = fs::current_path();

    // Print the path to stdout
    std::cout << "generic: " << cwd.generic_string() << '\n';
    std::cout << "native: " << cwd.string() << '\n';
    std::cout << "quoted: " << cwd << '\n';
    std::cout << "Components: \n";
    for (const auto& dir : cwd) {
        std::cout <<'[' <<dir.string() << ']'; // each part
    }
    std::cout << '\n';
    return 0;
}

boost_thread.cpp

#include <boost/asio/io_service.hpp>
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
#include <boost/make_shared.hpp>
#include <iostream>

class Bla{
 public:
	void callback(std::string msg) {
		std::cout << msg << std::endl;
		usleep(1000000);
	}

	Bla() {
		/*
		 * This will start the io_service_ processing loop. All tasks
		 * assigned with io_service_->post() will start executing.
		 */
		io_service_ = boost::make_shared<boost::asio::io_service>();
		work_ = boost::make_shared<boost::asio::io_service::work>(*io_service_);
		/*
		 * This will add 2 threads to the thread pool. (You could just put it in a for loop)
		 */
		std::size_t my_thread_count = 2;
		for (std::size_t i = 0; i < my_thread_count; ++i){
			threadpool_.create_thread(boost::bind(&boost::asio::io_service::run, io_service_));
		}
	};

	void run() {
		/*
		 * This will assign tasks to the thread pool.
		 * More about boost::bind: "http://www.boost.org/doc/libs/1_54_0/libs/bind/bind.html#with_functions"
		 */
		io_service_->post(boost::bind(&Bla::callback,this, "Hello World!"));
		io_service_->post(boost::bind(&Bla::callback,this, "./cache"));
		io_service_->post(boost::bind(&Bla::callback,this, "twitter,gmail,facebook,tumblr,reddit"));

	};

	void stop() {
		/*
		 * This will stop the io_service_ processing loop. Any tasks
		 * you add behind this point will not execute.
		 */
		io_service_->stop();
		/*
		 * Will wait till all the threads in the thread pool are finished with
		 * their assigned tasks and 'join' them. Just assume the threads inside
		 * the threadpool_ will be destroyed by this method.
		 */
		threadpool_.join_all();
	};

 private:
	/*
	 * Create an asio::io_service and a thread_group (through pool in essence)
	 */
	boost::shared_ptr<boost::asio::io_service> io_service_;
	boost::shared_ptr<boost::asio::io_service::work> work_;
	boost::thread_group threadpool_;

};

int main(int argc, char **argv) {
	Bla b;
	b.callback("test");
	b.run();

	usleep(3000000);
	b.stop();
	return 0;
}

CMakeLists.txt

cmake_policy(SET CMP0048 NEW)

# project name and language
project(boost_test VERSION 1.0.0 LANGUAGES CXX)

# set minimum cmake version
cmake_minimum_required(VERSION 3.16)

# required C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Boost
find_package( Boost 1.82 COMPONENTS program_options system thread log filesystem REQUIRED )

include_directories( ${Boost_INCLUDE_DIR} )

include_directories("${CMAKE_CURRENT_SOURCE_DIR}")

set(SOURCES
    #boost_ex.cpp
    #boost_filesystem.cpp
    boost_thread.cpp
)

add_executable(boost_test
    ${SOURCES})

#target_link_libraries(boost_test
#    LINK_PUBLIC ${Boost_LIBRARIES}
#)

target_link_libraries(boost_test
    PUBLIC
        Boost::program_options
        Boost::filesystem
        Boost::thread
)

target_compile_options(boost_test
    PUBLIC
        -Wall
        $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
)

target_compile_features(boost_test
    PRIVATE
        cxx_std_17
        cxx_explicit_conversions
)
⚠️ **GitHub.com Fallback** ⚠️