howto add a static library (.a) into a C++ program?

前端 未结 1 1964
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 10:39

i want to know how i can use a static library in C++ which i created, first the lib:

// header: foo.h
int foo(int a);

.

//          


        
1条回答
  •  失恋的感觉
    2021-01-11 11:28

    You want:

    g++ -L.  prog.cpp -lfoo
    

    Unfortunately, the ld linker is sensitive to the order of libraries. When trying to satisfy undefined symbols in prog.cpp, it will only look at libraries that appear AFTER prog.cpp on the command line.

    You can also just specify the library (with a path if necessary) on the command line, and forget about the -L flag:

    g++ prog.cpp libfoo.a
    

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