Solved

Unresolved external symbol

Posted on 1998-11-05
8
6,267 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
ID: 1177020
>>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
ID: 1177021
Simply add 'wsock32.lib' to your project.
0
 

Accepted Solution

by:
jhendrix earned 50 total points
ID: 1177022
The 'wsock32.lib' will not remove all of your unresolved externals.
You should add 'Ws2_32.lib' to your project.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:wmlim060298
ID: 1177023
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
 
LVL 22

Expert Comment

by:nietod
ID: 1177024
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
ID: 1177025
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
ID: 1177026
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
ID: 1177027
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

679 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