Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

Tags:

c++

linker

I don't know what's wrong with it.. I can't find where the error is, commenting out the implementation doesn't resolve the error either.

Header File

#ifndef MAIN_SAVITCH_SEQUENCE_H #define MAIN_SAVITCH_SEQUENCE_H #include <cstdlib>  // Provides size_t  namespace main_savitch_3 {     class sequence     {     public:         // TYPEDEFS and MEMBER CONSTANTS         typedef double value_type;         typedef std::size_t size_type;         static const size_type CAPACITY = 30;         // CONSTRUCTOR         sequence( );         // MODIFICATION MEMBER FUNCTIONS         void start( );         void advance( );         void insert(const value_type& entry);         void attach(const value_type& entry);         void remove_current( );         // CONSTANT MEMBER FUNCTIONS         size_type size( ) const;         bool is_item( ) const;         value_type current( ) const;     private:         value_type data[CAPACITY];         size_type used;         size_type current_index;     }; }  #endif 

Source

#include "sequence1.h" #include <assert.h>  namespace main_savitch_3 {      // Default constructer - sequence is empty     sequence::sequence()     {         used = current_index = 0;     }       // Start the iteration     void sequence::start()     {         current_index = 0;     }     // Iterate     void sequence::advance()     {         current_index++;     }       // Number of items in the sequence     sequence::size_type sequence::size() const     {         return used;     }     // Checks if there is a current item     bool sequence::is_item() const     {         return current_index <= used && used > 0;     }     // Returns the current value     sequence::value_type sequence::current() const     {         assert(is_item()); // no current item         return data[current_index];     }       // Adds an item BEFORE the current index     void sequence::insert(const value_type& entry)     {         assert(entry != 0); // pointer is invalid         assert(current_index < sequence::CAPACITY); // no room to add an item          // move items up - starting with the last item and working down to the current item         // arrays start at 0, so the -1 adjusts it         for (size_type i = used - 1; i >= current_index; i--)             data[i + 1] = data[i];          data[current_index] = entry;     }     // Adds an item AFTER the current index     void sequence::attach(const value_type& entry)     {         assert(entry != 0); // pointer is invalid         assert(current_index < sequence::CAPACITY); // no room to add an item          // move items up - starting with the last item and working down to the current item         // arrays start at 0, so the -1 adjusts it         for (size_type i = used - 1; i > current_index; i--)             data[i + 1] = data[i];          if (current_index = 0)             data[used] = entry;         else             data[current_index + 1] = entry;     }     // Removes the current item     void sequence::remove_current()     {         for (size_type i = current_index; i < used; i++)             data[i] = data[i + 1];     }  } 
like image 346
Caleb Jares Avatar asked Jan 30 '11 20:01

Caleb Jares


People also ask

How do I fix unresolved external symbol in C++?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do I fix LNK1120?

The LNK1120 message comes last, and shows the unresolved symbol error count. You don't need to fix this error. This error goes away when you correct all of the LNK2001 and LNK2019 linker errors before it in the build output.

How do I fix unresolved external symbol LNK2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .

How to fix the linker error in Visual Studio 2010?

15 Answers 15 ActiveOldestVotes 83 Even if your project has a main()method, the linker sometimes gets confused. You can solve this issue in Visual Studio 2010 by going to Project -> Properties -> Configuration Properties -> Linker -> System and changing SubSystemto Console. Share Improve this answer

How to fix the linker error when using twinmain?

If you are using tWinMain as your main function, you must include tchar.h or change it to either WinMain or wWinMain depending on whether or not your app is Unicode. Failure to do so also yields this linker error even with the correct subsystem. (/SUBSYSTEM:WINDOWS) This helped me, apart from that I also had to disable Avast anti-virus.

Why is my main () function not working?

The reason you might be recieving this error may be because you originally created a new header file.h and then renamed it to file.cpp where you placed your main() function. To fix the issue right click file.cpp -> click Properties go to


1 Answers

Even if your project has a main() method, the linker sometimes gets confused. You can solve this issue in Visual Studio 2010 by going to

Project -> Properties -> Configuration Properties -> Linker -> System

and changing SubSystem to Console.

like image 106
Caleb Jares Avatar answered Oct 03 '22 01:10

Caleb Jares