mixing c file with c++ file

This is a discussion on mixing c file with c++ file within the C++ Programming forums, part of the General Programming Boards category; Hi, I have two projects and want them to get together. But I have a problem with mixing c and ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    mixing c file with c++ file

    Hi,

    I have two projects and want them to get together. But I have a problem with mixing c and c++ files.

    I get this error while compiling:

    process.c fatal error C1853: 'Debug/service.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)

    I try to solve my problem with this ms paper:
    http://support.microsoft.com/kb/126717
    but nothing there really work.

    Can somebody help me with this problem.


    Thank you for help,
    keeper

    p.s. I use MS Visual Studio 2003 and its internal compiler.
    Last edited by keeper; 06-24-2007 at 04:45 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Goto project settings and turn OFF pre-compiled headers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    Quote Originally Posted by Salem View Post
    Goto project settings and turn OFF pre-compiled headers.
    Hmm now I get these errors after I mark the option Not Using Precompiled Headers:

    cerrno(18): error C2143: syntax error : missing '{' before ':'

    and

    cerrno(18): error C2059: syntax error : ':'

    and

    cstdlib(19): fatal error C1003: error count exceeds 100; stopping compilation

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Are you including any of your headers before the system headers?

    Did you delete the "Debug" and "Release" directories, then try "Rebuild All..." ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    Quote Originally Posted by Salem View Post
    Are you including any of your headers before the system headers?

    Did you delete the "Debug" and "Release" directories, then try "Rebuild All..." ?
    I have under the option Additional Dependencies these two psapi.lib ntdll.lib libaries.

    The only header I include before the system headers is #include "stdafx.h"

    I delete the Debug directory rebuild all, but I have the same errors I mentioned above.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    Making a complete new project without the stdafx.cpp and stdafx.h file and with Not Using Precompiled Headers on, I get these errors:

    test error LNK2005: _strcat already defined in ntdll.lib(ntdll.dll)

    test error LNK2005: _atoi already defined in ntdll.lib(ntdll.dll)

    test error LNK2019: unresolved external symbol "int __cdecl InjectDll(void *,char const *,int)" (?InjectDll@@YAHPAXPBDH@Z) referenced in function "void __stdcall ServiceMain(unsigned long,char * * const)" (?ServiceMain@@YGXKQAPAD@Z)

    test error LNK2019: unresolved external symbol "void * __cdecl GetProcessHandle(unsigned long)" (?GetProcessHandle@@YAPAXK@Z) referenced in function "void __stdcall ServiceMain(unsigned long,char * * const)" (?ServiceMain@@YGXKQAPAD@Z)

    Can you help me with this better?

  7. #7
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    you have to make sure all your libraries and your project are using the same threading/linking model

    i.e Multi-threaded debug DLL, or Multi-threaded DLL, or Mutli-threaded debug (static) or Multi-threaded (static)

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    Quote Originally Posted by Darryl View Post
    you have to make sure all your libraries and your project are using the same threading/linking model

    i.e Multi-threaded debug DLL, or Multi-threaded DLL, or Mutli-threaded debug (static) or Multi-threaded (static)
    I have test all the different versions available, but I get always the error LNK2005 and error LNK2019 I write in my post above.

    And I dont know what type of lib ntdll.lib is.

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    If somebody can please download the programm one could better see were my problems are. I don't know what I can describe more about the errors that appear because everything I try to solve the problem get me new errors. Probably its a little fault in the code and with the programm you see it better as with my description of that.

    Thank you,
    keeper

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    get it working

    It was just a little
    Code:
    extern "C"
    {
    	#include "x.h"
    }
    Thank you all for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

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