?????????????????mylib.c??????????:
????/* mylib.c */
??????i nclude
????void foo()
????{
????printf("%s"??"I am from mylib!/n");
????}
??????
????cl /c /MLd mylib.c
??????????????/MLd????????libcd.lib????????lib.exe??VC???????????????????????????????????????????
????lib /OUT:my.lib mylib.obj
??????mylib.obj???????????????????my.lib??????????main.c???:
????/* main.c */
????void foo();
????int main()
????{
????foo();
????return 0;
????}
??????
????cl /c main.c
?????????????
????link main.obj my.lib
????????????????????????????????main.exe?????????LNK2005??LNK1169 ????????????????????????????:"warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library"??????????????????????????????????????????????Щ???
????????E??U??D????????????????????赽main.obj??????????E?????????δ??????foo????U????main????D????????? main.obj???????????libc.lib?????????????????????????б???β?????????my.lib?????????????????????U?е????з???(??????????foo)??my.lib?е???????????(??????????mylib.obj)????????????????鶨????U?е???????? mylib.obj????????foo??????????????E??foo??U????D??mylib.obj?????printf????U???????? mylib.obj??????????????libcd.lib?????????????????????б???β(??libc.lib?????)?????????my.lib???????????е????????U?е????????U??D??????仯????????????????????????????????????????????????????????????libc.lib????????????libc.lib???printf.obj??????printf??????printf??U???D????printf.obj??????E????????????з??????D?????????δ???????????U???????????????????????????Щ????????????????????(????crt0.obj??)????????????????(????malloc.obj??free.obj??)???????E?У???????U??D????????仯???????????????????????δ?????????????????????????????????壬????????????????libc.lib???U????????????libcd.lib????????U????????????????????????????????????????????????裬?????E?е??????鰱?????????????
?????????????????????????????????汾????????????????????????????????????????????????????μ????????
???????mylib.c?????????:
??????include
????void foo()
????{
????// just a test ?? don"t care memory leak
????_malloc_dbg( 1?? _NORMAL_BLOCK?? __FILE__?? __LINE__ );
????}
????????_malloc_dbg????ANSI C??????????????VC?????????malloc?????棬???????????????????????????????????????????????_DEBUG???????????????????????malloc????????
????cl /c /MLd mylib.c
????lib /OUT:my.lib mylib.obj
???????????????????
????link main.obj my.lib
?????????????????????????????????????LNK2005????????"fatal error"??LNK1169?????????????????LNK4098???????????????????????????????????????????????????????????????????????°????
????????E??U??D?????????????main.obj??????????E????foo????U????main????D????libc.lib???????????????б???β?????????my.lib??foo??U????D??_malloc_dbg????U??libcd.lib??????????????б??β?????????? libc.lib?????????libc.lib???κ?????????鶼??ж???_malloc_dbg(???????????????д???)????????????κ??????????_malloc_dbg??????E??????????????????????????(??crt0.obj??)????????????????(????malloc.obj?? free.obj??)????????????E?У???U??D??????????????仯????????????????libc.lib???U??_malloc_dbg??????????????libcd.lib??????dbgheap.obj??????_malloc_dbg??????dbgheap.obj????E?????????δ???????????U??????????????????????????D?????????????????malloc??????????D??(????libc.lib???malloc.obj????E???????)????dbgheap.obj??????????malloc???????????????????????????????????????????ж?????????????
?????????????????????????????????Σ???????????????????????????????????????汾????μ???????(main.obj)?????? (my.lib)????????????????????????????????????/MLd??????????main.c??????/ML????????mylib.c??
???????????????У???????п?my.lib???????(mylib.c)??????????ò??????????±?????Щ???????δ??????????????????????????????????????????????и???????????????????????Щ????????????????????????????????????????VC???????С???????????????????dumpbin.exe?????????????????
????dumpbin /DIRECTIVES my.lib
??????????????????Щ"Linker Directives"????????????????????????????????????????????????"-defaultlib:XXXX"?????????????????XXXX????????????????????????
???????????????????????????????ú?????????????????ó??????????LNK2005??LNK1169 ??????????IDE????????????????? "Project????" -> "C/C++" -> "????????(code generation)" -> "???????(run-time library)" ??????????ó???????????汾????????????????Ч??????????
???????????
?????? Project/Setting/Link/General?е? Project Options: ???? /FORCE:MULTIPLE???ɡ?