Cannot add file .c to C++ project

This is a discussion on Cannot add file .c to C++ project within the C++ Programming forums, part of the General Programming Boards category; I add file C to C++ project. They show error massage. I add this file Mytest.h and Mytest.c Mytest.h have ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Cool Cannot add file .c to C++ project

    I add file C to C++ project. They show error massage.

    I add this file
    Mytest.h and Mytest.c

    Mytest.h have this detail

    #ifdef __cplusplus
    extern "C" {
    #endif

    int TestMe(int, int);

    #ifdef __cplusplus
    }
    #endif


    Mytest.c have this detail

    #include "Mytest.h"

    int TestMe(int x, int y)
    {
    return x+y;
    }

    I use Visual C++ 6.0 add this C file to my C++ project . There are error message like this

    --------------------Configuration: BExtract - Win32 Debug--------------------
    Compiling...
    Mytest.c
    e:\microcomputer\mytest.c(10) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.
    Creating browse info file...
    BSCMAKE: error BK1506 : cannot open file '.\Debug\Mytest.sbr': No such file or directory
    Error executing bscmake.exe.

    BExtract.exe - 2 error(s), 0 warning(s)

    Do you know the reason of error? How to solve the problem?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    7

    Post

    Hm, try nameing your Mytest.c to "MyTest.cpp" or if that don't work than open MSVC++ File>New> Win32 Api console then after you have done that go File>New> C++ Source code and then just open your MyTest.h

    hope I'm not too confusing

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    you could just rename it to .cpp like he said, because everything valid in C is valid in C++.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >because everything valid in C is valid in C++.
    Ahahahahahahaha!

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    are you laughing at me?!?!? its true....

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >are you laughing at me?!?!? its true....
    No, I was laughing at your statement. Valid C is not valid C++, despite what you may have been told there are distinct differences. For the most part C code will compile as C++, but not always. The infamous malloc code for example:
    ptr = malloc ( n * sizeof *ptr );

    This is how it should be written in C, yet C++ will flag errors since malloc has no cast. You don't want to change the C code just so that it can compile as C++ because in C if you cast malloc you are causing a potential problem instead of solving one.

    -Prelude
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    seriously?? i gotta try that :P. excuse my ignorance .

  8. #8
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    >e:\microcomputer\mytest.c(10) : fatal error C1010: unexpected >end of file while looking for precompiled header directive

    Turn off precompiling. I dunno where but a guy had this problem too and they told him to do just that. Try searching for that thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. How do I add .C Project to my complier?
    By php111 in forum C Programming
    Replies: 82
    Last Post: 10-03-2008, 04:12 PM
  4. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  5. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21