Solved

Unresolved external symbol

Posted on 1998-11-05
8
6,239 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now