?
Solved

Linker Prblem: Unresolved external '_main'...

Posted on 1996-12-26
1
Medium Priority
?
793 Views
Last Modified: 2010-08-05
I just got Borland's C++ 5.0, and tried to compile a very simple windows program (just a skelton, really).  It compiles fine, but while linking, Make fails with the error message "Unresolved external '_main' referenced from module c0nt.ASM"  It did this with Borland's Hello Wold example, too.  What is wrong?
0
Comment
Question by:dcunning122196
1 Comment
 

Accepted Solution

by:
JaimeLich earned 100 total points
ID: 1162189
The particular linker error you experienced is an unresolved external reference message which means a symbol-the name of any function, class, struct, union, typedef, or variable-such as a global variable or non-static function name was used in a source file that did not contain the definition for the symbol (i.e. the function body for a function and the actual non-extern point of declaration for a global variable). Normally not having the declaration and definition of a symbol in a given source file is okay as long as the symbol is defined in another source file. This is one of the jobs which the linker does. The linker keeps track of all "unresolved external references" (a reference is any time the name of a symbol is used in a source file) and tries to find a defintion that matches each of the references. So for example you might have a program that is made up of two source files called say src1.cpp and src2.cpp. In src1.cpp you define and give the body for a function called foo and then src2.cpp you give the prototype of foo and then you make a function call to foo somewhere in the code of src2.cpp. When the compiler comes across the function call to foo when compiling src2.cpp it searchs the rest of the code of src2.cpp to find the segment of code where the body of foo is defined. Now since foo is not defined in src2.cpp the compiler makes a special mark in the resulting object file that basically says the "symbol foo is an external reference that needs to be resolved". After both files have been compiled the linker comes into to play in order to link external references with their defenitions. So when the linker comes across the special mark left by the compiler in the object file of src2.cpp it searchs the object file of src1.cpp for the body of foo. Now since the body of foo was defined in src1.cpp the linker is able to resolve the reference by changing the mark in the object file of src2.cpp into an address in memory which points to where the body of foo begins. But if there had been no definition for foo in src1.cpp or in any other compiled source file then the mark in the object file for src1.cpp would still be there and an "unresolved external symbol referenced" error whould be flagged.

From the error you have described it sounds as if none of your source files has the body for a function named "main" (which is required of all C/C++ programs). My guess is that you may be only compiling one of the source files needed for the program and so you need a project file that includes the multiple source files that you need in creating an executable file. With a project file you will be able to let the linker know that you have more then one file that needs to be compiled and linked and so the compiler and linker will properly utilize all the source files in creating an executable.




0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

621 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