cant run a different main function in c++

Thomas Timana 0 Reputation points
2024-04-07T13:29:47.95+00:00

Hello, i have a project with 2 cpp files, the c++.cpp file and the ciclos.cpp file, c++.cpp file has a main function and ciclos.cpp file has another main function named main_2, im trying to run main_2 function in the ciclos.cpp file but visual studio only runs the main function in the c++.cpp file.User's image

User's image

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,569 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 10,436 Reputation points Microsoft Vendor
    2024-04-08T02:03:20.1466667+00:00

    Hi, @Thomas Timana

    If you want to run main_2 instead of main as the entry point, you need to set the entry point:

    //turn off /RTC*
    #pragma runtime_checks("", off)
    //add entry point
    #pragma comment(linker, "/ENTRY:main_2")
    //add runtime lib
    #pragma comment(lib,"ucrtd.lib")
    #pragma comment(lib,"vcruntimed.lib")
    

    Console sample:

    #include<iostream>
    // turn off /RTC*
    #pragma runtime_checks("", off)
    #pragma comment(linker, "/ENTRY:main_2")
    #pragma comment(lib,"ucrtd.lib")
    #pragma comment(lib,"vcruntimed.lib")
    int  main_2()
    {
        std::cout << "hello main 2";
        return 0;;
    }
    int main()
    {
        std::cout << "hello main 1 ";
        return 0;
    }
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.