How to force use of static library over shared?

后端 未结 2 1559
谎友^
谎友^ 2021-01-04 05:39

In my SConscript I have the following line:

Program(\"xtest\", Split(\"main.cpp\"), LIBS=\"mylib fltk Xft Xinerama Xext X11 m\")

How do I g

2条回答
  •  佛祖请我去吃肉
    2021-01-04 06:40

    Passing the full filepath wrapped in a File node will force static linking. For example:

    lib = File('/usr/lib/libfoo.a')
    Program('bar', 'main.c', LIBS = [lib])
    

    Will produce the following linker command line

    g++ -o bar main.o /usr/lib/libfoo.a
    

    Notice how the "-l" flag is not passed to the linker for this LIBS entry. This effectively forces static linking. The alternative is to modify LINKFLAGS to get what you want with the caveat that you are bypassing the library dependency scanner -- the status of the library will not be checked for rebuilds.

提交回复
热议问题