我目前正在尝试使用MacOS High Sierra上的GCC编译包含多个文件的项目。由于某些原因,我收到以下错误:
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 302.3 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0 -fdebug-compilation-dir /Users/emmanuel/Desktop/ITC/C/Arrays/stackoverflow -ferror-limit 19 -fmessage-length 151 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/j5/1q3h2809043fnwb6c83ycj9c0000gn/T/main-0c855d.o -x c main.c
clang -cc1 version 9.0.0 (clang-900.0.38) default target x86_64-apple-darwin17.0.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include
/Library/Developer/CommandLineTools/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0 -o a.out /var/folders/j5/1q3h2809043fnwb6c83ycj9c0000gn/T/main-0c855d.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_myFunction", referenced from:
_main in main-0c855d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的代码(我简化了它,因此它更具可读性。我检查过它实际上会产生上面的错误):
的main.c
#include "myfile.h"
int main(int argc, char *argv[]){
printf("Hello World!\n");
myFunction();
return 0;
}
myfile.h
#include <stdio.h>
void myFunction();
myfile.c文件
#include "myfile.h"
void myFunction(){
printf("Worked!\n");
}
你知道这个问题可以来自哪里吗?
谢谢!