Wednesday, July 1, 2009

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

Check following. ( with boost library )

one of the stupid thing you might have done is that you did not had a main function. (try compiling following code)

#include <boost\regex.hpp>
#include <iostream>
#include <string>

int main (int argc, char ** argv[])
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }

    return 0;
}


1. you need to have the Configuration Properties > linker > system = Console

2. Linker > General  > additional libraries pointing to your libraries directory " the boost *.lib" ex. C:\Program Files\boost\boost_1_38\lib

3. C/C++ > General > Additional Included Directories "Points to the boost folder" ex.C:\Program Files\boost\boost_1_38\

- Mihir Patel

3 comments:

Anonymous said...

Thank you very much! I made the very stupid mistake of having a Main function instead of a main function... It would have had me stumped for a very long time if I didn't find this page.

Michael C said...

I also made the same stupid mistake. I feel better knowing that i am no the only one.

Anonymous said...

Well you guys have the jump on me, cause I have a main function but still get this error. Can't find any reference to a linker anywhere (using Visual Studio 2010). Maybe i should have passed on the lobotomy.