原文网址:http://blog.csdn.net/newchenxf/article/details/51743181
转载请注明出处。


1 前言

gcc 编译, 有个选项是-static, 它有什么作用呢? 这主要决定, 编译-链接时, 使用的库是静态库还是动态库.

先补充一下静态库和动态库的背景.
一个模块要对外提供能力, 先有个头文件, 定义接口。 然后是库文件, 包含接口的实现。库可以是静态库和动态库。两者的区别如下:

1.1 静态库(常以a为结尾, 例如libxx.a):

在链接时将需要的二进制代码都“拷贝”到可执行文件中(注意, 只拷贝需要的,不会全部拷贝)。
优点: 编译成功的可执行文件可以独立运行,而不再需要向外部要求读取函数库的内容;
缺点: 维护难, 每次更新, 都需要依赖方重新编译。 另外, 依赖方因为拷贝了库的内容, 所以编译后的文件会比较大。

1.2 动态库(常以so为结尾, 例如libxx.so):

链接时仅仅“拷贝”一些重定位和符号表信息,这些信息可以在程序运行时完成真正的链接过程。
优点: 维护容易, 只要对外接口不变, 则库可以不停的更新, 依赖方不需要再次编译;
缺点: 依赖方运行时需要所有依赖的so库都存在。

所以两者的本质区别:
该库是否被编译进目标(程序)内部。

2 例子

比如,现在有个简单的程序。该程序依赖于pthread
这个非常常见的线程模块, 在我的ubuntu的电脑的头文件和库如下:


chenxiaofeng@chenxiaofeng-HP-EliteBook-840-G3:/usr/include$ ls -la pthread.h
-rw-r--r-- 1 root root 41269 1月  24 20:53 pthread.hchenxiaofeng@chenxiaofeng-HP-EliteBook-840-G3:/usr/lib/x86_64-linux-gnu$ ls -la libpthread*
-rw-r--r-- 1 root root 6254274 1月  24 20:53 libpthread.a
-rw-r--r-- 1 root root     252 1月  24 20:53 libpthread.so

这个简单的程序如下:

#include <stdio.h>
#include <pthread.h>/* this function is run by the second thread */
void *thread_exe(void *x_void_ptr)
{/* increment x to 100 */int *x_ptr = (int *)x_void_ptr;while(++(*x_ptr) < 100);printf("x increment finished\n");return NULL;
}int testFunc(int param)
{printf(" testFunc %i\n",param);pthread_t inc_x_thread;int x = 0, y = 0;/* create a second thread which executes thread_exe(&y) */if(pthread_create(&inc_x_thread, NULL, thread_exe, &x)) {fprintf(stderr, "Error creating thread\n");return 1;}/* increment y to 100 in the first thread */while(++y < 100);printf("y increment finished\n");/* wait for the second thread to finish */if(pthread_join(inc_x_thread, NULL)) {fprintf(stderr, "Error joining thread\n");return 2;}/* show the results - x is now 100 thanks to the second thread */printf("x: %d, y: %d\n", x, y);return 0;
}int main(int argc, char* argv[])
{int a = 100;testFunc(a);return 1;
}

2.1 加static编译的情况

编译:

gcc test_main.c -static -o test_main -lpthread

结果,你会发现test_main文件很大!

chenxf@chenxf-PC:~/temp/test_main$ ll
-rwxrwxr-x  1 chenxf chenxf 1131418  6月 23 14:45 test_main*
-rw-rw-r--  1 chenxf chenxf    1081  6月 23 14:38 test_main.c

这是因为,编译选择的是静态链接, 查找的库是libpthread.a, 生成目标文件, 会把各种依赖pthread的函数,比如pthread_create()函数,以及所有pthread_create()依赖的任何东西,从libpthread.a拷贝进来。 这样, 运行test_main不需要依赖任何库了!

不信??你可以用这个命令看:

nm test_main

结果一大堆,我截取一下:

0000000000404fb0 T __pthread_cleanup_push
0000000000404fb0 T _pthread_cleanup_pushw _pthread_cleanup_push_deferw __pthread_cleanup_upto
0000000000402fb0 W pthread_create
0000000000402fb0 T __pthread_create_2_1
0000000000405870 T __pthread_current_priority
00000000006d6dd8 B __pthread_debug
0000000000405060 T __pthread_disable_asynccancel
0000000000405000 T __pthread_enable_asynccancel
00000000006d6df0 B __pthread_force_elision
0000000000405fe0 T __pthread_get_minstack
0000000000404cf0 T __pthread_getspecific
0000000000404cf0 T pthread_getspecific
00000000006ceec0 D __pthread_init_array
0000000000405cc0 T __pthread_initialize_minimal
0000000000405cc0 T __pthread_initialize_minimal_internal
0000000000402790 T __pthread_init_static_tls
0000000000404070 T pthread_join
0000000000404c50 T __pthread_key_create
0000000000404c50 T pthread_key_create
0000000000404cb0 T pthread_key_delete
00000000006d0d80 B __pthread_keys
00000000006d6e24 B __pthread_multiple_threads
00000000004041b0 T __pthread_mutex_lock
00000000004041b0 T pthread_mutex_lock
0000000000400390 t __pthread_mutex_lock_full
0000000000404430 T __pthread_mutex_trylock
0000000000404430 T pthread_mutex_trylock
0000000000404b60 T __pthread_mutex_unlock
0000000000404b60 T pthread_mutex_unlock
0000000000400917 t __pthread_mutex_unlock_full
0000000000404a80 T __pthread_mutex_unlock_usercnt
0000000000404f10 T __pthread_once
0000000000404f10 T pthread_oncew __pthread_rwlock_destroyw __pthread_rwlock_initw __pthread_rwlock_rdlockw __pthread_rwlock_unlockw __pthread_rwlock_wrlockw pthread_setcancelstate
0000000000404d70 T __pthread_setspecific
0000000000404d70 T pthread_setspecific
0000000000405550 T __pthread_tpp_change_priority
00000000004061c0 T __pthread_unwind
0000000000406200 W __pthread_unwind_next
00000000004200c0 t ptmalloc_init.part.7
0000000000419fd0 t ptmalloc_lock_all
000000000041aac0 t ptmalloc_unlock_all
000000000041a0e0 t ptmalloc_unlock_all2
00000000004131c0 W puts
0000000000420b00 W pvalloc
0000000000420b00 T __pvalloc
0000000000411c30 T qsort
0000000000411900 T qsort_r
000000000044faa0 T _quicksort
000000000044fa30 T raise
000000000042d2f0 T rawmemchr
000000000042d2f0 T __rawmemchr
00000000006d7500 B _r_debug
000000000043ec60 W read
000000000043ec60 W __read
000000000040f190 t read_alias_file
0000000000469010 W readdir
0000000000469010 T __readdir
0000000000469010 W readdir64
0000000000469010 T __readdir64
00000000004099f0 t read_encoded_value_with_base
000000000040b410 t read_encoded_value_with_base
0000000000400e79 t read_int
00000000004013cb t read_int
000000000043ec69 T __read_nocancel
0000000000469aa0 T __readonly_area
0000000000406a40 t read_sleb128
0000000000409790 t read_sleb128
000000000041f830 T realloc
000000000041f830 T __realloc
000000000041ec50 t realloc_check
00000000006cf870 V __realloc_hook
00000000004204d0 t realloc_hook_ini
00000000006d6b40 b receiver
0000000000401ef0 T __reclaim_stacks
000000000049d3e0 W recvmsg
000000000049d3e0 W __recvmsg
000000000049d3e9 T __recvmsg_nocancel
0000000000441cf0 T __register_atfork
000000000040af60 T __register_frame
000000000040af50 T __register_frame_info
000000000040aed0 T __register_frame_info_bases
000000000040b010 T __register_frame_info_table
000000000040af90 T __register_frame_info_table_bases
000000000040b020 T __register_frame_table
0000000000459490 T __register_printf_function
0000000000459490 W register_printf_function
000000000045b000 T __register_printf_modifier
000000000045b000 W register_printf_modifier
00000000004593a0 T __register_printf_specifier
00000000004593a0 W register_printf_specifier
000000000045b380 T __register_printf_type
000000000045b380 W register_printf_type
0000000000401900 t register_tm_clones
00000000004002c8 r __rela_iplt_end
00000000004001d8 r __rela_iplt_start
00000000006d67e0 b release_handle
0000000000474590 t remove_slotinfo
00000000006d6500 B _res
000000000046aa30 T __res_iclose
0000000000442310 T __res_init
00000000006d74f8 B __res_initstamp
00000000004423b0 T __res_maybe_init
000000000046ab60 T __res_nclose
000000000046aa00 T __res_ninit
0000000000000000 D __resp
000000000046aa10 T __res_randomid
0000000000469c60 t res_setoptions.isra.0
000000000049fbb0 t res_thread_freeres
0000000000406220 t __restore_rt
0000000000469fd0 T __res_vinit
0000000000469120 T rewinddir
00000000004644e0 W rindex
00000000006d5490 b root
000000000048c9b0 t round_and_return
000000000048f790 t round_and_return
0000000000492190 t round_and_return
00000000006cefa0 d rtld_search_dirs
00000000006d6a80 b rule_dstoff
00000000006d6a90 b rule_stdoff
0000000000411d20 T __run_exit_handlers
00000000006d59e0 b run_fp
00000000006d6ca0 b running
00000000006d6dd0 b samples
00000000006d5b10 b save_arena
00000000004173a0 t save_for_backup
0000000000462b90 t save_for_wbackup.isra.0
00000000006d5b20 b save_free_hook
00000000006d5b30 b save_malloc_hook
000000000043f6a0 W sbrk
000000000043f6a0 T __sbrk
00000000006cf0c0 D __sched_fifo_max_prio
00000000006cf0d0 D __sched_fifo_min_prio
000000000043ea50 T __sched_getparam
000000000043ea50 W sched_getparam
000000000043ead0 T __sched_get_priority_max
000000000043ead0 W sched_get_priority_max
000000000043eaf0 T __sched_get_priority_min
000000000043eaf0 W sched_get_priority_min
000000000043ea90 T __sched_getscheduler
000000000043ea90 W sched_getscheduler
000000000043ea70 T __sched_setscheduler
000000000043ea70 W sched_setscheduler
000000000043eab0 T __sched_yield
000000000043eab0 W sched_yield
000000000040a270 t search_object
0000000000451080 W secure_getenv
00000000006d4f88 b seen_objects
000000000049d440 W sendto
000000000049d440 W __sendto
000000000049d449 T __sendto_nocancel
0000000000450d70 W setenv
0000000000450d70 T __setenv
000000000044f980 T __setfpucw
000000000049dea0 W setitimer
000000000049dea0 T __setitimer
00000000004111f0 T _setjmp
000000000044de10 T setlocale
0000000000406440 W sigaction
0000000000406440 T __sigaction
0000000000405b60 t sigcancel_handler
0000000000405bf0 t sighandler_setxid
000000000044fa00 T __sigjmp_save
0000000000411200 W siglongjmp
00000000004112b0 W sigprocmask
00000000004112b0 T __sigprocmask
000000000044f9a0 T __sigsetjmp
0000000000409980 t size_of_encoded_value
00000000004a6320 r slashdot.9308
000000000049d4a0 W socket
000000000049d4a0 T __socket
00000000004b6bba r sort_mask_chars
000000000045b500 T sscanf
000000000045b500 T __sscanf
00000000006cf0a0 d stack_cache
00000000006d0d60 b stack_cache_actsize
00000000006d0d50 b stack_cache_lock
00000000006cefe0 D __stack_prot
00000000006cf090 d stack_used
00000000006d0d30 B __stack_user
00000000006d5560 b stage
000000000040189e T _start
00000000004bf3d0 R __start___libc_atexit
00000000004bf3d8 R __start___libc_thread_subfreeres
0000000000402c40 t start_thread
00000000006d694c b state
00000000006d6954 b state
00000000006d695c b state
00000000006d6c08 b state
00000000006d6bc0 b static_buf
00000000006d4fa0 b static_slotinfo
00000000006d6df8 B __static_tls_align_m1
00000000006d6e00 B __static_tls_size
00000000006cf808 D stderr
00000000006cf818 D stdin
00000000006cf810 D stdout
00000000004b44e0 r step0_jumps.11680
00000000004b4e00 r step0_jumps.11706
00000000004b43e0 r step1_jumps.11711
00000000004b4d00 r step1_jumps.11737
00000000004b42e0 r step2_jumps.11712
00000000004b4c00 r step2_jumps.11738
00000000004b41e0 r step3a_jumps.11713
00000000004b4b00 r step3a_jumps.11739
00000000004b3fe0 r step3b_jumps.11715
00000000004b4900 r step3b_jumps.11741
00000000004b40e0 r step4_jumps.11716
00000000004b4a00 r step4_jumps.11742
00000000004b3ee0 r step4_jumps.11870
00000000004b4800 r step4_jumps.11895
00000000004bf3d8 R __stop___libc_atexit
00000000004bf3e8 R __stop___libc_thread_subfreeres
0000000000427310 i stpcpy
0000000000427310 i __stpcpy
0000000000427350 T __stpcpy_sse2
000000000043b0e0 T __stpcpy_sse2_unaligned
00000000004392a0 T __stpcpy_ssse3
0000000000427480 i strcasecmp
0000000000427480 i __strcasecmp
000000000042b2d0 T __strcasecmp_avx
0000000000427430 i __strcasecmp_l
0000000000427430 i strcasecmp_l
000000000042b2e0 T __strcasecmp_l_avx
000000000043dd00 T __strcasecmp_l_nonascii
00000000004274f0 T __strcasecmp_l_sse2
0000000000429730 T __strcasecmp_l_sse42
00000000004359b0 T __strcasecmp_l_ssse3
00000000004274e0 T __strcasecmp_sse2
0000000000429720 T __strcasecmp_sse42
00000000004359a0 T __strcasecmp_ssse3
0000000000421910 i strchr
000000000042d500 W strchrnul
000000000042d500 T __strchrnul
0000000000421940 T __strchr_sse2
000000000043b790 T __strchr_sse2_no_bsf
0000000000421b60 i strcmp
0000000000421ba0 T __strcmp_sse2
000000000042ea10 T __strcmp_sse2_unaligned
0000000000422fe0 T __strcmp_sse42
000000000042d7b0 T __strcmp_ssse3
0000000000423d90 i strcpy
0000000000423dd0 T __strcpy_sse2
000000000043aab0 T __strcpy_sse2_unaligned
0000000000437af0 T __strcpy_ssse3
0000000000423eb0 W strdup
0000000000423eb0 T __strdup
00000000004816d0 T strerror
0000000000464140 T __strerror_r
0000000000464140 W strerror_r
00000000006d7590 b string_space
00000000006d5528 b string_space_act
00000000006d5520 b string_space_max
0000000000400e07 t strip
0000000000423f00 T strlen
0000000000494da0 i strncasecmp
0000000000494da0 i __strncasecmp
0000000000499420 T __strncasecmp_avx
0000000000494d50 i __strncasecmp_l
0000000000494d50 i strncasecmp_l
0000000000499430 T __strncasecmp_l_avx
000000000049d330 T __strncasecmp_l_nonascii
0000000000494e10 T __strncasecmp_l_sse2
0000000000497460 T __strncasecmp_l_sse42
000000000049ade0 T __strncasecmp_l_ssse3
0000000000494e00 T __strncasecmp_sse2
0000000000497450 T __strncasecmp_sse42
000000000049add0 T __strncasecmp_ssse3
00000000004240c0 T strncmp
0000000000481750 i strncpy
0000000000481810 T __strncpy_sse2
0000000000484490 T __strncpy_sse2_unaligned
0000000000481910 T __strncpy_ssse3
00000000004640f0 W strndup
00000000004640f0 T __strndup
00000000004642c0 W strnlen
00000000004642c0 T __strnlen
0000000000494cb0 T strpbrk
00000000004644e0 T strrchr
0000000000481790 W strsep
0000000000481790 T __strsep
0000000000481790 T __strsep_g
00000000004263d0 i strstr
0000000000425e10 T __strstr_sse2
000000000043d220 T __strstr_sse2_unaligned
000000000048c690 W strtod
000000000048c680 T __strtod_internal
0000000000491eb0 W __strtod_l
0000000000491eb0 W strtod_l
000000000048fc60 T ____strtod_l_internal
000000000048c660 W strtof
000000000048c650 T __strtof_internal
000000000048f4b0 W __strtof_l
000000000048f4b0 W strtof_l
000000000048ce40 T ____strtof_l_internal
00000000004510b0 T strtol
000000000048c6c0 W strtold
000000000048c6b0 T __strtold_internal
0000000000494780 W __strtold_l
0000000000494780 W strtold_l
0000000000492600 T ____strtold_l_internal
00000000004510a0 T __strtol_internal
00000000004510b0 W strtoll
0000000000451580 W __strtol_l
0000000000451580 W strtol_l
00000000004510d0 T ____strtol_l_internal
00000000004510a0 T __strtoll_internal
0000000000451580 W __strtoll_l
0000000000451580 W strtoll_l
00000000004510d0 T ____strtoll_l_internal
00000000004b3c40 R __strtol_ul_max_tab
00000000004b3c00 R __strtol_ul_rem_tab
000000000048c6e0 t str_to_mpn.isra.0
000000000048f4c0 t str_to_mpn.isra.0
0000000000491ec0 t str_to_mpn.isra.0
00000000004510b0 W strtoq
00000000004120b0 T strtoul
00000000004120a0 T __strtoul_internal
00000000004120b0 W strtoull
0000000000412520 W __strtoul_l
0000000000412520 W strtoul_l
00000000004120d0 T ____strtoul_l_internal
00000000004120a0 T __strtoull_internal
0000000000412520 W __strtoull_l
0000000000412520 W strtoull_l
00000000004120d0 T ____strtoull_l_internal
00000000004120b0 W strtouq
00000000006d4dd0 b subs.9002
000000000040bb10 T __syscall_error
000000000040bb13 T __syscall_error_1
000000000043e360 W sysconf
000000000043e360 T __sysconf
000000000043e280 t __sysconf_check_spec
00000000004bd980 V _sys_errlist
00000000004bd980 V sys_errlist
00000000004bd980 R __sys_errlist_internal
00000000004bd980 R _sys_errlist_internal
00000000004bddb8 V _sys_nerr
00000000004bddb8 V sys_nerr
00000000004bddb8 R __sys_nerr_internal
00000000004bddb8 R _sys_nerr_internal
00000000004b7540 r system_dirs
00000000004b7520 r system_dirs_len
000000000041ab70 t systrim.isra.1
0000000000469810 W tcgetattr
0000000000469810 T __tcgetattr
00000000004400f0 W tdelete
00000000004400f0 T __tdelete
0000000000441410 W tdestroy
0000000000441410 T __tdestroy
000000000043f890 t tdestroy_recurse
00000000004b90e0 R __tens
00000000004bf040 R _tens_in_limb
00000000006d4dc8 b terminator.8845
00000000004019ee T testFunc
00000000006d6c30 b textsize
00000000004400a0 W tfind
00000000004400a0 T __tfind
000000000049fe68 R _thread_db_const_thread_area
000000000049fe98 R _thread_db_dtv_dtv
000000000049fe8c R _thread_db_dtv_t_pointer_val
000000000049fea4 R _thread_db_link_map_l_tls_modid
000000000049ff4c R _thread_db_list_t_next
000000000049ff40 R _thread_db_list_t_prev
000000000049fef8 R _thread_db___nptl_initial_report_events
000000000049ff04 R _thread_db___nptl_last_event
000000000049ff10 R _thread_db___nptl_nthreads
000000000049ffac R _thread_db_pthread_cancelhandling
000000000049fe80 R _thread_db_pthread_dtvp
000000000049ff7c R _thread_db_pthread_eventbuf
000000000049ff70 R _thread_db_pthread_eventbuf_eventmask
000000000049ff64 R _thread_db_pthread_eventbuf_eventmask_event_bits
000000000049febc R _thread_db_pthread_key_data_data
000000000049feb0 R _thread_db_pthread_key_data_level2_data
000000000049fec8 R _thread_db_pthread_key_data_seq
000000000049feec R _thread_db___pthread_keys
000000000049fed4 R _thread_db_pthread_key_struct_destr
000000000049fee0 R _thread_db_pthread_key_struct_seq
000000000049ffe8 R _thread_db_pthread_list
000000000049ff58 R _thread_db_pthread_nextevent
000000000049ffc4 R _thread_db_pthread_pid
000000000049ffdc R _thread_db_pthread_report_events
000000000049ff94 R _thread_db_pthread_schedparam_sched_priority
000000000049ffa0 R _thread_db_pthread_schedpolicy
000000000049ff88 R _thread_db_pthread_specific
000000000049ffb8 R _thread_db_pthread_start_routine
000000000049ffd0 R _thread_db_pthread_tid
000000000049fe70 R _thread_db_sizeof_list_t
000000000049fe7c R _thread_db_sizeof_pthread
000000000049fe70 R _thread_db_sizeof_pthread_key_data
000000000049fe6c R _thread_db_sizeof_pthread_key_data_level2
000000000049fe70 R _thread_db_sizeof_pthread_key_struct
000000000049fe74 R _thread_db_sizeof_td_eventbuf_t
000000000049fe78 R _thread_db_sizeof_td_thr_events_t
000000000049ff1c R _thread_db_td_eventbuf_t_eventdata
000000000049ff28 R _thread_db_td_eventbuf_t_eventnum
000000000049ff34 R _thread_db_td_thr_events_t_event_bits
00000000004019ae T thread_exe
0000000000465f60 T time
0000000000486520 W timelocal
00000000006d5ba8 b timestamp.10239
00000000006d6980 V timezone
00000000006d6980 B __timezone
00000000006d7540 B _tmbuf
00000000006d0cc8 D __TMC_END__
00000000004a4280 r to_mb
000000000041b1a0 t top_check
00000000006d6c70 b tos
00000000004a4300 r to_wc
0000000000469a50 W towctrans
0000000000469a50 T __towctrans
000000000040c320 t transcmp
00000000006d75a8 b transitions
00000000004b1760 r translit_from_idx
00000000004aed00 r translit_from_tbl......

你会发现,和thread相关的各种各样的东西,全部来了!而不仅仅是pthread_create().

2.2 不加-static的情况

而如果你不加-static,结果就不同了。

gcc test_main.c -o test_main -lpthread

文件要小很多!

chenxf@chenxf-PC:~/temp/test_main$ ll
-rwxrwxr-x  1 chenxf chenxf  8891  6月 23 14:39 test_main*
-rw-rw-r--  1 chenxf chenxf  1081  6月 23 14:38 test_main.c

用nm查看,会发现东西就少很多。

chenxf@chenxf-PC:~/temp/test_main$ nm test_main
0000000000601060 B __bss_start
0000000000601068 b completed.6973
0000000000601050 D __data_start
0000000000601050 W data_start
00000000004006b0 t deregister_tm_clones
0000000000400720 t __do_global_dtors_aux
0000000000600e08 t __do_global_dtors_aux_fini_array_entry
0000000000601058 D __dso_handle
0000000000600e18 d _DYNAMIC
0000000000601060 D _edata
0000000000601070 B _end
0000000000400934 T _fini
0000000000400740 t frame_dummy
0000000000600e00 t __frame_dummy_init_array_entry
0000000000400b30 r __FRAME_END__U fwrite@@GLIBC_2.2.5
0000000000601000 d _GLOBAL_OFFSET_TABLE_w __gmon_start__
00000000004005d8 T _init
0000000000600e08 t __init_array_end
0000000000600e00 t __init_array_start
0000000000400940 R _IO_stdin_usedw _ITM_deregisterTMCloneTablew _ITM_registerTMCloneTable
0000000000600e10 d __JCR_END__
0000000000600e10 d __JCR_LIST__w _Jv_RegisterClasses
0000000000400930 T __libc_csu_fini
00000000004008c0 T __libc_csu_initU __libc_start_main@@GLIBC_2.2.5
000000000040088c T mainU printf@@GLIBC_2.2.5U pthread_create@@GLIBC_2.2.5U pthread_join@@GLIBC_2.2.5U puts@@GLIBC_2.2.5
00000000004006e0 t register_tm_clones
0000000000400680 T _start
0000000000601060 B stderr@@GLIBC_2.2.5
00000000004007ad T testFunc
000000000040076d T thread_exe
0000000000601060 D __TMC_END__

其中部分关键段:

U printf@@GLIBC_2.2.5
U pthread_create@@GLIBC_2.2.5
U pthread_join@@GLIBC_2.2.5

U表示在本程序只是调用,没有定义,需要其他库支持。
T表示本程序定义。

3 总结

gcc 加上 -static,会在链接阶段, 查找对应模块的静态库, 而非动态库, 并把需要的东西,都带进目标文件),编译好后,文件会非常大,但是,运行时就不需要依赖任何动态库。

这种编译, 通常在开发阶段, 程序员使用, 很少用于量产产品喔

gcc -static 命令相关推荐

  1. GCC笔记 命令行分析

    1984年,Richard Stallman发起了自由软件运动,GNU (Gnu's Not Unix)项目应运而生,3年后,最初版的GCC横空出世,成为第一款可移植.可优化.支持ANSI C的开源C ...

  2. gcc/g++ 命令的常用选项

    gcc/g++ 命令的常用选项 使用g++编译CPP文件如果用gcc编译C++源文件时,加以下选项:-lstdc++,否则使用了C++操作的文件编译会出错.假如在程序中用到new delete操作,而 ...

  3. Linux GCC 常用命令

    Linux GCC 常用命令与汇编 文章目录 Linux GCC 常用命令与汇编 1 .简介 2 .简单编译 2.1 预处理 2.2 编译为汇编代码 2.3 汇编(Assembly) 2.4 连接(L ...

  4. Linux GCC常用命令和ELF文件格式

    Linux GCC常用命令和ELF文件格式 一.各种工具 (一)GCC编译工具 (二)Binutils (三)C 运行库 一. C 语言程序 Hello.c示例 (一)准备工作 (二)编译过程 1.预 ...

  5. Linux GCC常用命令

    目录 一.示例一 1.简单编译 1.1预处理 1.2编译为汇编代码 1.3汇编 1.4连接 2.多个程序文件的编译 3检错 4库文件连接 二.示例二 1.准备hello.c 2.预处理 3.编译 4. ...

  6. GCC常用命令与nasm

    目录 一.Linux GCC 常用命令 简单编译 预处理 编译为汇编代码(Compilation) 汇编(Assembly) 连接(Linking) 多个程序文件的编译 检错 库文件链接 编译成可执行 ...

  7. gcc编译命令的常用选项——强烈推荐大家使用 -Wall 选项

    C程序编编译的过程分为如下四个阶段 1.预处理:头文件展开(#include).宏替换(#define).条件编译(#ifdef)(.i)使用预处理器(预处理阶段处理的都是以#开头的代码) 2.编译: ...

  8. GCC常用命令及GCC编译器背后的故事

    文章目录 一. GCC常用命令 1. 简介 2. 简单编译 2.1 预处理 2.2 编译为汇编代码(Compilation) 2.3 汇编(Assembly) 2.4 连接(Linking) 3. 多 ...

  9. gcc常用命令与gcc编译器背后的故事

    目录 1 gcc常用命令 1.1 简介 1.2 简单编译 1.2.1 预处理 1.2.2 编译为汇编代码(Compilation) 1.2.3 汇编(Assembly) 1.2.4 连接(Linkin ...

最新文章

  1. 罗伯特扫地机器人电池如何取_irobot扫地机器人电池怎么拆 iRobot/艾罗伯特扫地...
  2. c#获取本地ip地址网关子网掩码_教你如何修改路由器LAN口IP地址的方法
  3. 使用css实现点击切换效果
  4. 中相对路径与绝对路径的写法_相对路径和绝对路径?简洁易懂解释+实例
  5. linux gdb模式下无反应,Linux,GDB 嵌入式Linux的GDB远程调试的问题--断点没反应
  6. Java 反射取类中类_Java反射机制(二):通过反射取得类的结构
  7. 河工计算机学院抖肩舞,来了来了!河工大版抖肩舞已上线~
  8. anaconda清华镜像源使用
  9. 猎头如何做大单,赚大钱?
  10. SIM卡的PIN码(CHV)及对应的APDU命令
  11. win7显示500服务器错误,搞定win10系统提示http500内部服务器错误的解决步骤
  12. 一台计算机地址线32根,若有一台计算机,它的地址线有32根,则它的寻址空间是...
  13. 如何自己制作简历模板?简历在线制作的方法介绍
  14. 夺命雷公狗—玩转SEO---44---外链群发原理
  15. [机缘参悟-95] :不同人生和社会问题的本质
  16. 阿里巴巴集团增持阿里影业股权完成交割
  17. 一个c语言源程序至少包括哪些内容,一个c源程序中至少应包括一个什么函数_后端开发...
  18. 西南大学计算机研究生就业好嘛,西南大学2018毕业生就业结果:就业率为 89.45%,最高月薪7600...
  19. 【运算放大器】反相放大电路仿真应用
  20. AndroidO Treble架构下HIDL服务查询过程

热门文章

  1. WPF绑定中的OneWay和TwoWay区别和适用场景
  2. “地图易“图层管理工具介绍——业务图层管理轻松搞定
  3. LCD与LED的区别是什么?
  4. 京城最惨地产商:股价跌到8毛1,滞留海外曾为女星豪掷1亿
  5. 国外各大学和学院对于ChatGPT使用立场总结
  6. java web 下载文件名乱码
  7. ti84计算机游戏,[转载]Ti-83 和84 计算器如何求方程的根--考AP微积分的同学一定要看,请...
  8. 内网外网同时使用——双网关设置
  9. 【宫水三叶的刷题日记】730. 统计不同回文子序列(困难)
  10. CSS高级篇——过渡动画