Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error LNK2001: unresolved external symbol __main

Status
Not open for further replies.

croakyfrog

Technical User
Dec 4, 2001
51
GB
has anyone seen and does anyone know a fix for the message: error LNK2001: unresolved external symbol __main?

thank-you :eek:)
 
This more ofter than not means you haven't imported a library needed for API calls. Make sure you do this in Project Settings- check MSDN for the library needed for the APIs you use.
 
sorry for being a bit thick but im quite new to all of this - how do i find out which apis i use (im debugging someone elses code and i dont know much)
 
hi, such message comes out when you have system problem:
it cannot out during normal compiling ops.
C language, differs from other in one essential things:
no funcions are part of language, also main() is external

In language there are only structure-control-program as
for, while, do... +- ecc.

When a compiler-link development tool is well installed,
main, is automatically found (normally it stays in libc)
Strange functions ( as math ) can be resolved only
including -lm in cl (DOS) or cc (Unix) command line.

If unresolved function is main() I belive that you are
writing a program outside Visual Studio env : is this right?

If you are at command line, have you launched VCVARS32.bat
( you find it under a \bin dir under Pr.Files\ VuslaStudio..

Are you using .c or .cpp file ?

bye
 
I just ran into the same problem, building an ATL dll.
Problem only exist when building any of the release versions.

Project is created / defined using wizards.

Removing the "_ATL_MIN_CRT" from the project settings (Preprocessor definitions) seems to solve the problem.
/JOlesen
 
Further info from the help menu search:

Two goals you might hope to achieve when you use ATL are:

Minimizing your image size
Minimizing your reliance on run-time DLLs
However, you might want to take advantage of some functions provided by the CRT. Because statically linking increases your image size, and dynamically linking ties you to the run-time DLL, using the CRT may deprive you of these key goals for using ATL.

To help solve this dilemma, ATL provides a solution: the _ATL_MIN_CRT macro. The _ATL_MIN_CRT macro, activated by setting the General Property option Minimize CRT Use in ATL to Yes, provides alternative implementations for many of the common CRT functions that would otherwise require the CRT startup code.

Remember that using the _ATL_MIN_CRT macro does not guarantee that no functions from the CRT will be required. If you use a function that requires the CRT startup code to operate properly, you will get the following linker error:

LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
Providing your own implementation of _main does not solve this problem: you must either remove reliance on the functions that require the CRT startup code, or you must either statically link the startup code in your image or dynamically link to the CRT.



Surprising what infomation you can find by using the "HELP"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top