How to use C++ Boost library with pkg-config?

后端 未结 2 2068
清酒与你
清酒与你 2021-02-12 12:39

I successfully compiled and installed the latest version of the Boost library onto my linux machine. Now, I would like to be able to use pkg-config to ease the process of provid

相关标签:
2条回答
  • 2021-02-12 13:15

    Was facing a similar issue with boost. Wrote simple python script to generate a .pc file. Saved me the pain of having write all the linker commands. I've posted it on https://github.com/nmante/pkg-config-generator.

    Essentially, you give the script a directory where the library files are (.so, .a, .dylib files) and it will generate the linker commands (e.g. -lboost_graph). Feel free to tweak and fork to your needs.

    Here's a sample boost.pc file I generated for my machine (Mac OS X). You can tweak it manually, or you can use my github program to generate it on your machine.

    # Package Information for pkg-config
    
    prefix=/usr/local/Cellar/boost/1.60.0_2
    exec_prefix=${prefix}
    libdir=${exec_prefix}/lib
    includedir_old=${prefix}/include/boost
    includedir_new=${prefix}/include
    
    Name: Boost
    Description: Boost is awesome
    Version: 1.60.0
    Libs: -L${exec_prefix}/lib  -lboost_prg_exec_monitor-mt 
    -lboost_math_c99f-mt -lboost_unit_test_framework-mt 
    -lboost_container-mt -lboost_log_setup -lboost_math_tr1l 
    -lboost_graph-mt -lboost_wserialization-mt -lboost_log-mt 
    -lboost_math_c99f -lboost_type_erasure -lboost_signals-mt 
    -lboost_test_exec_monitor -lboost_filesystem -lboost_thread-mt 
    -lboost_math_tr1f-mt -lboost_date_time -lboost_timer 
    -lboost_math_tr1f -lboost_test_exec_monitor-mt -lboost_container 
    -lboost_math_tr1 -lboost_type_erasure-mt 
    -lboost_program_options-mt -lboost_graph -lboost_log_setup-mt 
    -lboost_random -lboost_system -lboost_system-mt -lboost_locale-mt 
    -lboost_wserialization -lboost_regex -lboost_exception 
    -lboost_timer-mt -lboost_signals -lboost_filesystem-mt 
    -lboost_math_c99-mt -lboost_math_tr1-mt -lboost_serialization-mt 
    -lboost_serialization -lboost_prg_exec_monitor -lboost_exception-mt 
    -lboost_coroutine -lboost_math_c99 -lboost_iostreams-mt 
    -lboost_random-mt -lboost_program_options -lboost_atomic-mt 
    -lboost_date_time-mt -lboost_math_c99l -lboost_math_tr1l-mt 
    -lboost_context-mt -lboost_regex-mt -lboost_coroutine-mt 
    -lboost_log -lboost_chrono-mt -lboost_wave-mt 
    -lboost_iostreams -lboost_chrono -lboost_unit_test_framework 
    -lboost_math_c99l-mt
    Cflags: -I${includedir_old} -I${includedir_new}
    
    0 讨论(0)
  • 2021-02-12 13:21

    What you're looking for seems to be a bit complicated, and a long-requested feature, as indicated in this 3 year old post https://svn.boost.org/trac/boost/ticket/1094 on Boost's trac. Reading through it shows that the feature was repeatedly postponed and never implemented (as of 1.4.3). The cause of the inability to generate a .pc file usable by pkg-config happens to do with boost's inconsistency in naming their library versions / build variants.

    FWIW, an alternative for "automating" your building process is to use autotools (autoconf/automake). There's a link that might be of use to you (which I can't post because SO thinks I'm a spammer instead of a newcomer!), just google "tsuna boost m4 github" and it should take you there :)

    0 讨论(0)
提交回复
热议问题