CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    191

    Adding existing C file to C++/MFC project



    Anyone ever try to add an existing C file to an existing C++/MFC project? When I do it, I get


    fatal error C1010: unexpected end of file while looking for precompiled header directive


    Ok, so I #include "stdafx.h" at the top. But then I get:


    fatal error C1853: 'Debug/GTest.pch' is not a precompiled header file created with this compiler


    Anyone have any ideas?

  2. #2
    Join Date
    Apr 1999
    Location
    Toronto, ON
    Posts
    713

    Re: Adding existing C file to C++/MFC project



    Hi! Goto to project settings-C++-precompiler header && disable it



  3. #3
    Join Date
    Apr 1999
    Posts
    30

    Re: Adding existing C file to C++/MFC project



    to cpp or c after stdafx.h I added

    #ifdef _DEBUG

    #define new DEBUG_NEW

    #undef THIS_FILE

    static char THIS_FILE[] = __FILE__;

    #endif

    =-----------

    to h file


    #if !defined(AFX_utils_h)

    #define AFX_utils_h


    #if _MSC_VER >= 1000

    #pragma once

    #endif // _MSC_VER >= 1000


    and I called my c file, .cpp. Everything works fine. If you want to use .c extension and compile, I guess you need to use Extern "c" Precompiler directive.

  4. #4
    Guest

    Re: Adding existing C file to C++/MFC project

    I encountered this problem recently. It was caused by building a pch file through stdafx.cpp and then including stdafx.h
    in a c file. This is why the message mentions "not a precompiled header file created with this compiler". In my case,
    I changed the .c file to a .cpp and it worked fine. If you don't want to do this, I think there is an option to use the C++
    compiler on C files and that should fix things. Good Luck.

    Gomez



  5. #5
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: Adding existing C file to C++/MFC project

    for the header file, add this:

    extern "C"
    {
    #include "the_c_header.h"
    }

    and before each function add

    extern "C"

    so if the old C funcion was:

    void myFunct(void)
    {

    }

    change it to:

    extern "C" void myFunc(void
    {

    }

    Rail


    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured