2009-08-18 5 views

답변

2

아래와 같이 링커 옵션 -static 만 사용하면됩니다.

[email protected]:/tmp$ cat helloworld.c 
#include <stdio.h> 

int main(void) { 
    printf("Hello, world\n"); 
} 
[email protected]:/tmp$ gcc -o helloworld.dyn helloworld.c 
[email protected]:/tmp$ gcc -static -o helloworld.static helloworld.c 
[email protected]:/tmp$ ls -l helloworld.* 
-rw-r--r-- 1 edd edd  69 2009-08-18 07:09 helloworld.c 
-rwxr-xr-x 1 edd edd 6667 2009-08-18 07:10 helloworld.dyn 
-rwxr-xr-x 1 edd edd 576348 2009-08-18 07:10 helloworld.static 
[email protected]:/tmp$ ./helloworld.dyn 
Hello, world 
[email protected]:/tmp$ ./helloworld.static 
Hello, world 
[email protected]:/tmp$ ldd helloworld.static 
     not a dynamic executable 
[email protected]:/tmp$ ldd helloworld.dyn 
     linux-gate.so.1 => (0xb7efc000) 
     libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7d83000) 
     /lib/ld-linux.so.2 (0xb7efd000) 
[email protected]:/tmp$ 
+0

Windows의 MinGW에서는 작동하지 않습니다. AFAIK, MinGW를 사용하여 MSVCRT.DLL에 대한 의존성을 피할 수있는 방법은 없습니다. 그러나 틀린 것으로 입증 되기는 어려울 것입니다. –

+0

아, 그래, 그 다른 OS. 최소한 나는 3 개 중 2 개를 다루었 다. –

+0

'-static'없이 연결하려고했는데, Win7에서 MinGW를 사용하고, 2 개의 다른 파일을 생성합니다 (정적 파일은 1.5Mo 이상입니다). 나는 전혀 전문가가 아니지만 잘 작동한다고 생각합니다 ... –

관련 문제