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

前端 未结 5 447
误落风尘
误落风尘 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条回答
  •  醉话见心
    2020-12-02 09:51

    I assume you are using gcc, to simply link object files do:

    $ gcc -o output file1.o file2.o
    

    To get the object-files simply compile using

    $ gcc -c file1.c
    

    this yields file1.o and so on.

    If you want to link your files to an executable do

    $ gcc -o output file1.c file2.c
    

提交回复
热议问题