Home > Blockchain >  How to use a library created using Bazel
How to use a library created using Bazel

Time:12-03

I'm relatively new to Cpp and I was trying to build a simple app for a quant project. I've managed to use Bazel to convert a chunk of my code to a library residing in the bazel-bin directory in my repository as a .lib file.

However, I'm not able to figure out how to use this library in my main.cpp which is outside the library I created. Could anyone help with this? Thanks!

CodePudding user response:

I'm not sure if I understood your question correctly, but I think, there is a .lib file that you want to use it (technically speaking, you need to link that .lib file to another app, or accessing in the main.cpp). Ok, it depends on what build-system you use.

for MSVC: Add the full path of the .lib file to Project Property Page -> Linker -> Input -> Additional Dependencies.
and don't forget to add the path to .h files (include path) to Project Property Page -> C/C -> General -> Additional Include Directories

It's the same for other build systems, you have to link it to the final built item.

for gcc there is a -L flag for the lib and a -h flag to point to the include directories.

in CMake:

include_directories(
    path/to/include/directory
)
link_directories(
    path/to/directory/that/lib/lives
)

add_executable(main main.cpp)

target_link_libraries(main lib_file_name)

if the lib file name is lib_file_name.lib you should not include .lib (just for cmake)

  • Related