Solved

Linker Prblem: Unresolved external '_main'...

Posted on 1996-12-26
1
773 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
JaimeLich earned 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 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.

749 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