b2 build group libs - Posted on Jun 21, 2024 - See https://www.bfgroup.xyz/b2 - Logs Home - d0025
Purpose:
I have many library targets, I don't want to link them by writting their names one by one, I want to make one name to all of them.
For example, I want to merge lib1, lib2, and lib3, and lib4 into one name target.
lib the_lib_name : src1.cpp src2.cpp : <cxxstd>23 ;
This will build a library libthe_lib_name.so with src1.cpp and src2.cpp, and the library target name is the_lib_name .
lib the_lib_name : : <name>the_name <search>/usr/local/lib : : <include>/usr/local/include ;
This will define a library target the_lib_name .
Because the source code list is empty, it will use prebuilt library .
<name>the_name , this means it will search name libthe_name.so
<search>/usr/local/lib, this means it will search path /usr/local/lib to find that libthe_name.so
<include>/usr/local/include, this means any other targets that depend this target will add -I/usr/local/include as their include path.
Many b2 jamfile rules follow parameter format like this:
rule_name param1 : param2 : param3 : param4 : param5 : param6 : ... : ... : ... ;
For example, the rule lib :
lib lib_name : source_code_list : requirements : default-build : usage-requirements ;
If the library search path is standard, the <search> can be empty.
lib lib3 : : <name>lib3 ; # Omit the <search>
Because the search path of libs is standard, the <search> can be omitted.
lib lib3 ;
This is the same as :
lib lib3 : : <name>lib3 ;
But if you want to use different target name and library name, you can not use that short code.
lib audio : : <name>lib3 ; # target name is audio, library name is lib3, aka. liblib3.so
To define many targets, nice:
lib lib3 lib2 lib1 ;
It is the same as:
lib lib3 : : <name>lib3 ; lib lib2 : : <name>lib2 ; lib lib1 : : <name>lib1 ;
alias target : target1 target2 target3 ;
So, I have my first solution:
lib lib1 lib2 lib3 lib4 ; alias liball : lib1 lib2 lib3 lib4 ; exe my_prog : my_prog.cpp : <library>liball <cxxstd>23 ;
const std::string greeting = "Cheers, c++!";
std::cout << greeting << std::endl;
std::cout << greeting.data() << std::endl;
caught:
=================================== # The c++ programming language. # # # # Join c++ # # Deck # ===================================