How do I link object files in C? Fails with “Undefined symbols for architecture x86_64”

前端 未结 5 439
误落风尘
误落风尘 2020-12-02 08:53

So I\'m trying trying to use a function defined in another C (file1.c) file in my file (file2.c). I\'m including the header of file1 (file1.h) in order to do this.

H

5条回答
  •  Happy的楠姐
    2020-12-02 09:36

    You could compile and link in one command:

    gcc file1.c file2.c -o myprogram
    

    And run with:

    ./myprogram
    

    But to answer the question as asked, simply pass the object files to gcc:

    gcc file1.o file2.o -o myprogram
    

提交回复
热议问题