C++ 错误LNK2019:函数\uuuuu\tMainCartStartup中引用了未解析的外部符号\u main

C++ 错误LNK2019:函数\uuuuu\tMainCartStartup中引用了未解析的外部符号\u main,c++,linker,C++,Linker,我不知道它怎么了。。我找不到错误在哪里,注释掉实现也不能解决错误 头文件 #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 CONSTANT

我不知道它怎么了。。我找不到错误在哪里,注释掉实现也不能解决错误

头文件

#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
#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];
    }

}
#如果主SAVITCH序列#
#定义主序列
#包含//提供大小\u t
名称空间main_savitch_3
{
类序列
{
公众:
//typedef和成员常量
typedef双值_类型;
typedef std::size\u t size\u type;
静态const size_类型容量=30;
//建造师
序列();
//修改成员函数
void start();
作废预付款();
无效插入(常量值、类型和条目);
无效附加(常量值、类型和条目);
无效删除当前的内容();
//常数成员函数
大小\类型大小()常数;
bool是项目()常量;
值\类型当前()常量;
私人:
值_类型数据[容量];
使用的尺寸和类型;
大小\类型当前\索引;
};
}
#恩迪夫
来源

#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
#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];
    }

}
#包括“sequence1.h”
#包括
名称空间main_savitch_3
{
//默认构造函数-序列为空
序列::序列()
{
使用=当前_索引=0;
}
//开始迭代
void序列::start()
{
当前_指数=0;
}
//迭代
void序列::advance()
{
当前_索引++;
}
//序列中的项目数
序列::大小\类型序列::大小()常量
{
使用的退货;
}
//检查是否存在当前项目
布尔序列::is_item()常量
{
返回当前_索引0;
}
//返回当前值
序列::值\类型序列::当前()常量
{
断言(is_item());//没有当前项
返回数据[当前_索引];
}
//在当前索引之前添加项
无效序列::插入(常量值\类型和条目)
{
断言(条目!=0);//指针无效
assert(current_index=当前\u索引;i--)
数据[i+1]=数据[i];
数据[当前索引]=条目;
}
//在当前索引后添加项
无效序列::附加(常量值\类型和条目)
{
断言(条目!=0);//指针无效
assert(current_index当前\u索引;i--)
数据[i+1]=数据[i];
如果(当前指数=0)
数据[使用]=输入;
其他的
数据[当前索引+1]=条目;
}
//删除当前项
无效序列::删除当前()
{
对于(大小\类型i=当前\索引;i<已使用;i++)
数据[i]=数据[i+1];
}
}

您需要一个
main()
函数,以便程序知道从何处开始。

您似乎没有main函数,而main函数应该是程序的入口点。

您实现了
main()
函数吗

int main(int argc, char **argv) {
    ... code ...
    return 0;
}
[编辑]

您的
main()
位于另一个源文件中,因此您可能忘记将其添加到项目中


要添加现有源文件:在解决方案资源管理器中,右键单击源文件文件夹,指向添加,然后单击现有项。现在选择包含
main()

的源文件,如果您的项目中有
\u tmain
函数,您需要
包括在内。

以防有人遗漏了明显的内容;请注意,如果您构建GUI应用程序并使用
“-subsystem:windows”在链接参数中,应用程序条目为WinMain@16. 不是main()。因此,您可以使用此代码段调用main():

#包括
#包括
#ifdef__GNUC__
#定义(stdcall)属性(stdcall)
#恩迪夫
int_stdcall
WinMain(结构HINSTANCE),
结构HINSTANCE\uu*hPrevInstance,
字符*lpszCmdLine,
国际展览(nCmdShow)
{
返回干管(_argc,_argv);
}

即使您的项目有一个
main()
方法,链接器有时也会感到困惑。您可以在VisualStudio2010中通过转到解决此问题

项目->属性->配置属性->链接器->系统


并将子系统更改为控制台。

转到“项目属性配置属性链接器输入其他依赖项”,然后转到末尾并键入“ws2_32.lib”。

我遇到了这个问题,尽管:

  • 有一个
    main()
    ;及
  • 将我的解决方案中的所有其他项目配置为静态库
我的最终解决方案如下:

  • 我的
    main()
    位于命名空间中,因此有效地调用了
    something::main()
    …删除此命名空间修复了问题

我在Visual Studio 2013中处理DLL项目时遇到LNK2019错误

我在项目中添加了一个新配置。但是VisualStudio没有将“配置类型”作为“动态库”,而是将其添加为“应用程序”。 这导致LNK2019错误

通过转到项目->属性->配置属性->常规并将“配置类型”更改为“动态库(.dll)”,将“目标扩展名”更改为“.dll”,修复了LNK2019错误

是的,最初的问题是关于控制台/应用程序项目的,这与我的回答不同。但我相信加上这个答案可能会有帮助
#undef main
#include <Windows.h>

int WINAPI  wWinMain(_In_ HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPWSTR    lpCmdLine,
    int       nCmdShow)
{
   return 0;
}
int main(int argc, char* argv[], char* environment[]){
      return 0;
}