Solved

Unresolved external symbol

Posted on 1998-11-05
8
6,224 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:wmlim060298
8 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
>>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"?)
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Simply add 'wsock32.lib' to your project.
0
 

Accepted Solution

by:
jhendrix earned 50 total points
Comment Utility
The 'wsock32.lib' will not remove all of your unresolved externals.
You should add 'Ws2_32.lib' to your project.
0
 

Author Comment

by:wmlim060298
Comment Utility
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!

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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().
0
 

Author Comment

by:wmlim060298
Comment Utility
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!
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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).
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now