• C

how to compile winsock program ?

I'm from a UNIX environment programmer and i faced a problem of compiling a socket program (it work on UNIX).
Currently i'm using borland C++4.5 and i'm trying to write a windows base socket program.

just some need info, is that enough just only include thw winsock.h header file ? or what else do i need ? any .lib file or .dll file ? if yes, how do i make a linking of it ?

error occur when i try to link the program, it said undefine symbol SOCKET in mysock.cpp

how should i solve that ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to link wsock32.lib or winsock.lib, depending on your compiler.
tsungAuthor Commented:
How should i make the linkage for the winsock.lib to my program if i'm using the borland c++ 4.5 compiler ?
This is proboly a dumb question but you do have SOCKET defined somewhere??  I use borland 4.5  I will see if I can't figure out how to do the linking.
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

tsungAuthor Commented:
I checked the winsock.h header file and there is a line of code ---> typedef unsigned int SOCKET
been defined in the header file.

is there any others possibility which cause this problem ?
  Search through your includes and code for any "strange" uses of "SOCKET".  It is just supposed to be a variable (uint).  But since you are getting linker errors, the compiler thinks that SOCKET is a function or some other block of code.

-=- James.

Linking winsock.lib or wsock32.lib didn't help? All socket symbols are defined there.
tsungAuthor Commented:
I have try the same program and same libraries and it work on MSVC 5.0. But how come Borland C can't do it ?
You never know the mysterious ways of compilers/linkers - what they include by default, what they include when they see something's missing, et cetera
This sounds like a serious question. Why don't you increase the points to 50 (at least)?
do you use 16bit API...?
Borland 4.x Linking is Differ


"Note that it doesn't matter whose Winsock you are using, the same .LIB file works with all 16 bit programs, and you don't need a .LIB for 32 bit programs. Also note that these versions are a bit more recent than the version in the WINSOCK.HLP normally shipped with BC++.
If you are using Borland C++ 4.0 you got a free WINSOCK.HLP and WINSOCK.H, but no WINSOCK.DLL, so your programs can't link. You can use the provided IMPLIB to make a WINSOCK.LIB from your WINSOCK.DLL."


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.