none
using MFC problems with an unresolved external in a .c file

    Question

  • Hi,

    I have created a MFC project and have added a win32 project to it and added C files to it. In the view class I have called a function in one of the c files. I have created a header for the C file where I have declared the function. I have created another header file which is in the view class. Which has in it:

    #include <windows.h>
    
    extern "C"
    {
    	#include  "win32 folder\theCFile.h"
    
    }

    On linking I am getting:

    error LNK2019: unresolved external symbol _server referenced in function "public: int __thiscall CSView::OnCreate(struct tagCREATESTRUCTW *)" (?OnCreate@CSView@@QAEHPAUtagCREATESTRUCTW@@@Z)

    1>...\Debug\ghS.exe : fatal error LNK1120: 1 unresolved externals

    Any clues as to what is causing this gratefully appreciated

    Thursday, April 11, 2013 3:07 PM

Answers

  • I have given up on this. Thanks for your help. I have decided microsoft does not like having a win32 project using C files dependent on a mfc project. I guess I have to start using .cpp files for new projects.
    This should not be necessary. If you use extern "C" in the header used with MFC, and have the same calling convention in both projects, it should work.
     
    There is nothing special about MFC projects in this regard.
     

    David Wilkinson | Visual C++ MVP
    Monday, April 15, 2013 2:14 PM

All replies

  • Looks like calling convention issue .use __stdcall

    Thanks


    Rupesh Shukla

    Thursday, April 11, 2013 3:10 PM
  • Thanks Rupesh, I have never had to use that before. I placed it in theCFile.h:

    include <windows.h>
    
    int _stdcall  server(void );
    
    

    But no joy!

    Thursday, April 11, 2013 3:26 PM
  • Seemed to have made some progress. I have made the mfc read the win32 static lib. Now I am getting this:

    >Linking...

    1>nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv

    1>nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc

    HELP!

    Thursday, April 11, 2013 4:33 PM
  • Hi,
     
    I have created a MFC project and have added a win32 project to it and added C files to it. In the view class I have called a function in one of the c files. I have created a header for the C file where I have declared the function. I have created another header file which is in the view class. Which has in it:
    What kind of project is the Win32 project? It needs to be a static (.lib) or dynamic (.dll) library project, and this project has to be linked to the MFC project.
     

    David Wilkinson | Visual C++ MVP
    Thursday, April 11, 2013 6:44 PM
  • Hi,

    Would you please provide us some codes about this?
    Like the function of CSView::OnCreate

    Or you can use show progress to check more detail information.

    Right click your project->Properties->Configuration Properties->Linker->General->Show Progress->Display all progress messages

    Then check information in output, see if some lib is wrong or missing.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 15, 2013 7:14 AM
  • Hi, it is a static library.

    What should I have done to add a win32 project to the MFC project? I am using VS 2008.

    Monday, April 15, 2013 10:08 AM
  • Hi, it is a static library.
     
    What should I have done to add a win32 project to the MFC project? I am using VS 2008.
    You do not add one project to another.
     
    Normally you would add the Win32 project to the solution, and link it to the MFC project. This linking will happen automatically if you list the Win32 project as a dependency of the MFC project, and have Link Library Dependencies set to Yes in
     
    Project Properties->Linker->General
     

    David Wilkinson | Visual C++ MVP
    Monday, April 15, 2013 10:22 AM
  • I have given up on this. Thanks for your help. I have decided microsoft does not like having a win32 project using C files dependent on a mfc project. I guess I have to start using .cpp files for new projects.

    Monday, April 15, 2013 1:25 PM
  • That's not true you can use .c file .Just create a static lib. and use it it should work.

    Thanks


    Rupesh Shukla

    Monday, April 15, 2013 1:54 PM
  • I have given up on this. Thanks for your help. I have decided microsoft does not like having a win32 project using C files dependent on a mfc project. I guess I have to start using .cpp files for new projects.
    This should not be necessary. If you use extern "C" in the header used with MFC, and have the same calling convention in both projects, it should work.
     
    There is nothing special about MFC projects in this regard.
     

    David Wilkinson | Visual C++ MVP
    Monday, April 15, 2013 2:14 PM
  • Hi I created a static library and it is still not working.
    Wednesday, April 17, 2013 8:35 AM
  • Hi I created a static library and it is still not working.

    When you say it's not working what you mean by that . Any error or anything else.

    Thanks


    Rupesh Shukla

    Wednesday, April 17, 2013 8:48 PM
  • Thanks Rupesh, there was always a static library. There were problems with the precompiled headers and they mysteriously fixed themselves (probably as a result of rebooting the computer - maybe?) then I had an issue on the linker. I had ignored in an attempt to solve an earlier problem which when added to the solution it worked.

    I do not use DLL's and am suprised that I have to use a static library.

    Thanks for your help.

    Sam 

    Thursday, April 18, 2013 8:05 AM
  • I do not use DLL's and am suprised that I have to use a static library.
    You don't. You should be able to use these C files in a DLL.
     

    David Wilkinson | Visual C++ MVP
    Thursday, April 18, 2013 12:16 PM
  • mysteriously fixed themselves ? There is no such thing in C++ named as magic . Defenately something get changed . Anyway if you are able to use it as static library then you can use it as dll . It will not create any issue for you . Just try it out by creating a simple Win32 Dll.

    Thanks


    Rupesh Shukla

    Thursday, April 18, 2013 2:14 PM