c++dllvisual-studio-2019lnk2019configurationproperties

LNK2019 From Unresolved External Symbol _main in MSVCRTD.lib For New DLL Project


I've begun a new C++ solution in Visual Studio 2019 which contains two projects (hereafter: project1 and project2).

Project1 is set as a DLL project and has no main() or _main() function. Project2 is set as the startup project and contains the main() function.

Project1 is receiving the following error on build:

CODE: LNK2019

DESCRIPTION: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

PROJECT: Project1

FILE: MSVCRTD.lib(exe_main.obj)

I've looked through some other similar issues on the site and the following info seems relevant:

I also notice that there is a related LNK1120 error below it (details below), for which the offending file is listed as "project1.exe", despite that my configuration type is set to DLL... Is there another place I need to set the project to be a DLL or remove a .exe reference?

CODE: LNK1120

DESCRIPTION: 1 unresolved externals

PROJECT: Project1

FILE: Project1.exe


Solution

  • Whoops: I forgot to remove the x86 platform from the project properties. For anyone experiencing this issue in the future:

    If you wish only to build for x64, from the properties dialogue select 'Configuration Manager'. Then expand the 'Active solution platform:' dropdown and select 'edit'. Select the configuration you wish to remove (x86 in my case) and select 'remove'. Then ensure that your 'Configuration Type' and 'SubSystem' are set appropriately on all remaining platforms. (If you select Platform: All Platforms' and check these values, they should not display 'different options'. (This fixed my issue.)

    If you wish to build for all platforms, ensure that the 'Configuration Type' and 'SubSystem' options are set on 'all platforms' and 'all configurations' in the project properties dialogue.

    Make sure to do the same for all projects in the solution you wish these changes to affect.