How can I force linking with a static library when a shared library of same name is present

后端 未结 3 1855
清歌不尽
清歌不尽 2020-12-24 11:46

Suppose I have a file main.cpp which uses sin() function which is defined in libmath. Also suppose that we have both libmath.a and lib

相关标签:
3条回答
  • 2020-12-24 12:12

    Use this function:

    g++ -o main main.cpp /path_to/libmath.a
    
    0 讨论(0)
  • 2020-12-24 12:32

    You'll need to pass the -static to the linker, but only for particular libraries you want. e.g.:

    g++ -o main main.cpp -Wl,-Bstatic -lmath -Wl,-Bdynamic
    
    0 讨论(0)
  • 2020-12-24 12:35

    If your linker supports -l:<filename> you may use:

    g++ -o main main.cpp -l:libmath.a
    
    0 讨论(0)
提交回复
热议问题