Solved

Linker Prblem: Unresolved external '_main'...

Posted on 1996-12-26
1
765 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 50 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  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 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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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

10 Experts available now in Live!

Get 1:1 Help Now