How do I link object files in C? Fails with "Undefined symbols for architecture x86_64"
c, compilation, gcc
Solution
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
Problem
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. However, I keep getting the following error whenever I try to compile my file using gcc: ``` Undefined symbols for architecture x86_64: "_init_filenames", referenced from: _run_worker in cc8hoqCM.o "_read_list", referenced from: _run_worker in cc8hoqCM.o ld: symbol(s) not found for architecture x86_64 ``` I've been told I need to "link the object files together" in order to use the functions from file1 in file2, but I have no clue what that means :(