linker woes - undefined reference

前端 未结 6 1007
北恋
北恋 2021-02-08 16:22

I\'m having a problem with my compiler telling me there is an \'undefined reference to\' a function I want to use in a library. Let me share some info on the problem:

6条回答
  •  旧时难觅i
    2021-02-08 16:59

    I guess you have to add the path where the linker can find the libraray. In gcc/ld you can do this with -L and libraray with -l.

    -Ldir, --library-path=dir

    Search directory dir before standard search directories (this option must precede the -l option that searches that directory).

    -larch, --library=archive

    Include the archive file arch in the list of files to link.


    Response to answers - there is no .a library file, just .h and .c in the library, so -l isn't approriate

    Then you may have to create the libraray first?

    gcc -c mylib.c -o mylib.o
    ar  rcs libmylib.a      mylib.o
    

提交回复
热议问题