libhello.c
#include <stdio.h>
void
hello(void)
{
printf("Hello, World!\n");
}
main.c를
extern void hello(void);
int
main(void)
{
hello();
return 0;
}
haidragondeMacBook-Air:2-8 haidragon$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
haidragondeMacBook-Air:2-8 haidragon$ which gcc
/usr/bin/gcc
haidragondeMacBook-Air:2-8 haidragon$ gcc -c ./main.c libhello.c
haidragondeMacBook-Air:2-8 haidragon$ ls
libhello.c libhello.o main.c main.o
haidragondeMacBook-Air:2-8 haidragon$ libtool -static -o libhell.a libhell.o
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: libhell.o (No such file or directory)
haidragondeMacBook-Air:2-8 haidragon$ libtool -static -o libhell.a libhello.o
haidragondeMacBook-Air:2-8 haidragon$ ls
libhell.a libhello.c libhello.o main.c main.o
haidragondeMacBook-Air:2-8 haidragon$ libtool -static -o libhello.a libhello.o
haidragondeMacBook-Air:2-8 haidragon$ rm libhell.a
haidragondeMacBook-Air:2-8 haidragon$ ls
libhello.a libhello.c libhello.o main.c main.o
haidragondeMacBook-Air:2-8 haidragon$ gcc -o main.static main.o libhello.a
haidragondeMacBook-Air:2-8 haidragon$ ls
libhello.a libhello.c libhello.o main.c main.o main.static
haidragondeMacBook-Air:2-8 haidragon$ ./main.static
Hello, World!
haidragondeMacBook-Air:2-8 haidragon$ otool -L ./main.static
./main.static:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
haidragondeMacBook-Air:2-8 haidragon$