Solved

Unresolved external symbol

Posted on 1998-11-05
8
6,247 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ question 3 65
C++ :Change value from  DisableCMD registry 4 59
Autosar OS Multicore Share Resources confusion ? 2 35
DCT of  2D array using fftw in c++ 9 38
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…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

776 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