Link to home
Start Free TrialLog in
Avatar of wmlim060298
wmlim060298

asked on

Unresolved external symbol

Hi,
I tried to compile and link my files and kept on getting this error. Is this caused by incorrect LIB file being used?  I am trying to write a Win32 console application. Do I inlucde the LIB in the Project Settings or add the LIB file into my workspace folder? Below is the list of errors I get when I add the LIB file in the workspace folder. Please bear with the long list of errors attached.

Linking...
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _WSAStartup@8
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _WSACleanup@0
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _inet_ntoa@4
smep.lib(smep.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _select@20
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__ntohl@4
smep.lib(smep_table.obj) : error LNK2001: unresolved external symbol __imp__gethostbyname@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__gethostbyname@4
smep.lib(smep_table.obj) : error LNK2001: unresolved external symbol __imp__gethostname@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__gethostname@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__socket@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__ioctlsocket@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__htons@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__accept@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__connect@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__recv@16
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__send@16
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__WSADuplicateSocketA@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__WSASocketA@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__bind@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__inet_addr@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__recvfrom@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__sendto@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__listen@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
LIBC.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Release/SMEPtestdos.exe : fatal error LNK1120: 28 unresolved externals
Error executing link.exe.

If I include the filename in the Project Settings I get this:
Linking...
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _WSAStartup@8
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _WSACleanup@0
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _inet_ntoa@4
smep.lib(smep.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
smep.lib(smep.obj) : error LNK2001: unresolved external symbol _select@20
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
smep.lib(smep_def.obj) : error LNK2001: unresolved external symbol __imp__ntohl@4
smep.lib(smep_table.obj) : error LNK2001: unresolved external symbol __imp__gethostbyname@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__gethostbyname@4
smep.lib(smep_table.obj) : error LNK2001: unresolved external symbol __imp__gethostname@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__gethostname@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__socket@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__ioctlsocket@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__htons@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__accept@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__connect@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__recv@16
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__send@16
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__WSADuplicateSocketA@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__WSASocketA@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__bind@12
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__inet_addr@4
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__recvfrom@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__sendto@24
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__listen@8
smep.lib(smep_socket.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
LIBC.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Release/SMEPtestdos.exe : fatal error LNK1120: 28 unresolved externals
Error executing link.exe.

Thank you.
Avatar of nietod
nietod

>>Do I inlucde the LIB in the Project Settings or add the LIB file
>> into my workspace folder?
I am pretty sure you can do either, but I find it easiest to add it to the project worskpace.  I let the IDE manage the libraries listed in the settings.  (The system libraries).

Where did the the library you are linking to come from?  Is it a C++ library?  If not, how did you declare the functions exported from it?  (Did you use extern "C"?)
Avatar of jkr
Simply add 'wsock32.lib' to your project.
ASKER CERTIFIED SOLUTION
Avatar of jhendrix
jhendrix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wmlim060298

ASKER

Thanks for the answers!

jhendrix,
I tried adding Ws2_32.lib into project settings, it's true that all the winsock errors are gone. However, there is still one error on LIBC.lib. See below.

IBC.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Release/SMEPtestdos.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

How do I solve this problem?
Thanks!

Does your program have a winmain() function?   Does if have the correct parameters? (depends on the compiler you are using).  Windows programs should have a WinMain() instead of a main().
nietod,
I tried to put "int WinMain()" intstead of just "int main()". I still got the following error messages.

"LIBC.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Release/SMEPtestdos.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe."

By the way, how should I use WinMain? I saw in the help topic that there is a need to include PrevInstance, hInstance, etc as the parameters, is it true that I must always put this in? I'm not sure how to implement WinMain, please advise.

Thanks!
You must declare WinMain with the exactly right parameters and return values.  Otherwise, you are declaring an overloaded WinMain (another version of WinMain) and the one the run-time library needs to call is still undefined.  

>> By the way, how should I use WinMain?
You use it just like you had used main().  There are different parameters.  If you don't need them, don't use them.  You don't get an argv or argcv parameters, like you do in main().  You can get the command line using the GetCommandLine() function.
I just noticed that you say this is a console application.   Actually--It isn't.  A console application does have a standard main() function not a WinMain().  If the linker is looking for a WinMain() it thinks it is creating a windows application, not a console application.  You will need to create a new project and specify the correct target type (win32 console, not win32 application).