0

I have a project containing both native and managed C++ code. Its runtime support is set to /clr. Its configuration type used to be set to Application, such that it compiled to an .exe. This worked all fine. But now I want to use this project as a library (.dll) for another project. So I change the configuration type to dynamic library and rename the main() function to something else. Then rebuilding the project gives the following two errors.

Error   2   error LNK1120: 1 unresolved externals   C:\Projects\MyProject\Source\Debug\MyProject.dll    MyProject
Error   1   error LNK2001: unresolved external symbol _main C:\Projects\MyProject\Source\CppSource\LINK     MyProject

The corresponding output is as follows.

1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>  Main.cpp
1>LINK : error LNK2001: unresolved external symbol _main
1>C:\Projects\MyProject\Source\Debug\MyProject.dll : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Am I forgetting something here?

chtenb
  • 14,924
  • 14
  • 78
  • 116
  • See some help here [C++/CLI and mixed mode programming](http://blogs.msdn.com/b/abhinaba/archive/2012/11/14/c-cli-and-mixed-mode-programming.aspx) – lsalamon Oct 15 '15 at 13:50
  • Are you referring to a specific section? It seems like a general guide to mixed mode. This question is specific to creating a dll from an exe project. – chtenb Oct 15 '15 at 13:56
  • 1
    Hard to imagine what could have gone wrong, this works without hassle when I try it. Be sure to change the configuration type for *all* configurations. And check the Linker > Advanced > Entry Point setting, it should be blank. – Hans Passant Oct 15 '15 at 14:23
  • The entry point setting seemed to have done the trick. Thanks a lot for the hint! – chtenb Oct 15 '15 at 14:29

1 Answers1

0

As Hans Passant suggested, the entry point setting must be blank.

This answer mainly exists to be able to mark this post as solved.

chtenb
  • 14,924
  • 14
  • 78
  • 116
  • 2
    Hmm, this is not a very useful answer. At least explain how this setting ended up having the wrong value so other programmers can avoid falling into the same trap. – Hans Passant Oct 15 '15 at 14:37
  • I'm not sure myself. The value was set to `main`, which used to be the entry point indeed. Maybe this value was set explicitly in the process of porting native code to managed code. – chtenb Oct 15 '15 at 14:41