Reputation: 6602
I created a library which makes use of winsocks, I compile it with following commands:
cl /c myLib.c /link ws2_32.lib
lib myLib.obj
thus obtaining myLib.lib, everything's ok.
Now, I wrote a test program, test.c in which I do:
#include "myLib.h"
//... i use some functions //
I compile it with
cl test.c /link myLib.lib
but I get:
myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_connec t@12 myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_htons@ 4 myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_inet_a ddr@4 myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_socket @12 myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_WSASta rtup@8 myLib.lib(myLib.obj) : error LNK2001: unresolved external symbol _imp_WSACle anup@0 logbus.lib(logbus.obj) : error LNK2001: unresolved external symbol _imp_closes ocket@4 test.exe : fatal error LNK1120: 7 unresolved externals
edit: Ok, if I compile adding a link to ws2_32.lib too it works. Anyway I don't like it: I already linked this library when I created mine, so I just want to link to myLib.lib...is it possibile?
Upvotes: 0
Views: 756
Reputation: 6602
I solved using the #pragma directive to include the win2_32 into myLib.lib.
Upvotes: 1
Reputation: 7074
You could try the advice in this answer, which is basically to include ws2_32.lib
in your own library:
cl /c myLib.c /link ws2_32.lib
lib /out:myLib.lib myLib.obj ws2_32.lib
In theory this would make a composite library. The issue, however, is if you distribute myLib.lib
- I'm not sure how legal it would be, as you would be including copyrighted code.
As an aside, but I include it as it's quite interesting and a slightly relevant, Raymond Chen recently wrote a series of articles on the Classical Linker Model.
Upvotes: 1