C/C++: how to figure out link flags?

后端 未结 1 1801
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 09:42

How do I reliably figure out link flags for libraries? I always end up googling/digging manuals.

Is there a way to list libraries available for linking, with names a

相关标签:
1条回答
  • 2021-01-13 10:41

    On most Linux systems, you can use pkg-config to list out the compiler options for a given library. For example:

    g++ example.cpp $(pkg-config --cflags --libs libpng)
    

    becomes

    g++ example.cpp -I/usr/include/libpng12 -lpng12
    

    Or an example with slightly more complicated output:

    $ pkg-config --cflags --libs gthread
    -D_REENTRANT -I/usr/include/glib-1.2 -I/usr/lib64/glib/include  -lgthread -lpthread -lglib
    
    0 讨论(0)
提交回复
热议问题