Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem with conditional compilation/manifest constants

illusionedillusioned Posts: 5Member
[b][red]This message was edited by illusioned at 2003-4-14 8:30:21[/red][/b][hr]
Good afternoon.

I am attempting to use #ifdef and #endif to conditionally select the proper precompiled header for the development environment/compiler I am using at any given moment. Currently, I am trying to compile a file for both Borland C++ Builder 6 and Microsoft Visual Studio .NET. At the head of the file I have two ifdef statements, one for borland, and one for microsoft. The code is as follows:

File: AdvLogSystem.h
---------------

#ifdef _MSC_VER //if this is MSVC
#include "stdafx.h" //use this header
#endif

#ifdef __BORLANDC__
#include "common.h" //if this is Borland, use "common.h"
#pragma hdrstop //again, borland specific
#endif

-------------

Borland C++ compiles this file without a problem, but MSVC gives me the following error:

#ifdef _MSC_VER
#include "stdafx.h"
#endif << ERROR HERE
LogSystem.cpp(5): fatal error C1020: unexpected #endif


I thought that maybe stdafx.h had it's own endif somewhere, but upon further inspection...
---------------------------------------------
the contents of stdafx.h are simple:

#pragma once

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include
------------------------------------------------
...I found that that was not the case. I thought maybe the #pragma once was causing the problem, but even with that removed I still get the same error. What do I do? I dont want to have to uncomment and recomment between applications that use different compilers!!


Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    [blue]stdafx.h cannot be in a conditional compile statement like that, at least I've never been able to get it to work. I've just removed the precompiled header stuff for projects that need to be compiled with two or more compilers.[/blue]


    : Good afternoon.
    :
    : I am attempting to use #ifdef and #endif to conditionally select the proper precompiled header for the development environment/compiler I am using at any given moment. Currently, I am trying to compile a file for both Borland C++ Builder 6 and Microsoft Visual Studio .NET. At the head of the file I have two ifdef statements, one for borland, and one for microsoft. The code is as follows:
    :
    : File: AdvLogSystem.h
    : ---------------
    :
    : #ifdef _MSC_VER //if this is MSVC
    : #include "stdafx.h" //use this header
    : #pragma hdrstop
    : #endif
    :
    : #ifdef __BORLANDC__
    : #include "common.h" //if this is Borland, use "common.h"
    : #pragma hdrstop //again, borland specific
    : #endif
    :
    : -------------
    :
    : Borland C++ compiles this file without a problem, but MSVC gives me the following error:
    :
    : #ifdef _MSC_VER
    : #include "stdafx.h"
    : #pragma hdrstop
    : #endif << ERROR HERE
    : LogSystem.cpp(5): fatal error C1020: unexpected #endif
    :
    :
    : I thought that maybe stdafx.h had it's own endif somewhere, but upon further inspection...
    : ---------------------------------------------
    : the contents of stdafx.h are simple:
    :
    : #pragma once
    :
    : #define WIN32_LEAN_AND_MEAN
    : #include <stdio.h>
    : #include
    : ------------------------------------------------
    : ...I found that that was not the case. I thought maybe the #pragma once was causing the problem, but even with that removed I still get the same error. What do I do? I dont want to have to uncomment and recomment between applications that use different compilers!!
    :

  • illusionedillusioned Posts: 5Member
    hmmm. The only problem with removing the stdafx.h line is that it's not hte whole project that im compiling with 2 compilers, more then this is a shared file between projects (like a foundation file). So if I remove the stdafx.h include if I ever want to use this file in MSVC I'll get

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

    Maybe my only solution is to include a file stdafx.h with all my projects regardless of whether or not im compiling with MSVC?


    : [blue]stdafx.h cannot be in a conditional compile statement like that, at least I've never been able to get it to work. I've just removed the precompiled header stuff for projects that need to be compiled with two or more compilers.[/blue]
    :
    :
    : : Good afternoon.
    : :
    : : I am attempting to use #ifdef and #endif to conditionally select the proper precompiled header for the development environment/compiler I am using at any given moment. Currently, I am trying to compile a file for both Borland C++ Builder 6 and Microsoft Visual Studio .NET. At the head of the file I have two ifdef statements, one for borland, and one for microsoft. The code is as follows:
    : :
    : : File: AdvLogSystem.h
    : : ---------------
    : :
    : : #ifdef _MSC_VER //if this is MSVC
    : : #include "stdafx.h" //use this header
    : : #pragma hdrstop
    : : #endif
    : :
    : : #ifdef __BORLANDC__
    : : #include "common.h" //if this is Borland, use "common.h"
    : : #pragma hdrstop //again, borland specific
    : : #endif
    : :
    : : -------------
    : :
    : : Borland C++ compiles this file without a problem, but MSVC gives me the following error:
    : :
    : : #ifdef _MSC_VER
    : : #include "stdafx.h"
    : : #pragma hdrstop
    : : #endif << ERROR HERE
    : : LogSystem.cpp(5): fatal error C1020: unexpected #endif
    : :
    : :
    : : I thought that maybe stdafx.h had it's own endif somewhere, but upon further inspection...
    : : ---------------------------------------------
    : : the contents of stdafx.h are simple:
    : :
    : : #pragma once
    : :
    : : #define WIN32_LEAN_AND_MEAN
    : : #include <stdio.h>
    : : #include
    : : ------------------------------------------------
    : : ...I found that that was not the case. I thought maybe the #pragma once was causing the problem, but even with that removed I still get the same error. What do I do? I dont want to have to uncomment and recomment between applications that use different compilers!!
    : :
    :
    :

  • Dazed66Dazed66 Posts: 77Member
    : hmmm. The only problem with removing the stdafx.h line is that it's not hte whole project that im compiling with 2 compilers, more then this is a shared file between projects (like a foundation file). So if I remove the stdafx.h include if I ever want to use this file in MSVC I'll get
    :
    : fatal error C1010: unexpected end of file while looking for precompiled header directive

    [blue]I don't know if this will work but I had this error one time and so I just turned off the precompiled headers. If you are using MSVC 6.0 go into Project->Settings. Next select your source file on the left. On the right side select the C/C++ tab and also select the Precompiled Headers under category. Last just select Not using Precompiled Headers. You will have to do the same for the release/debug version if it works.
    [/blue]

    :
    : Maybe my only solution is to include a file stdafx.h with all my projects regardless of whether or not im compiling with MSVC?
    :
    :

  • illusionedillusioned Posts: 5Member
    Thanks for all your input guys, you've been a great help. I think that I am just going to use the stdafx.h file no matter what I am compiling the file with, that way I can just use a blank header file for compiling under borland on gcc in linux, and actually use the file for the MSVC compile (because due to the size of some projects, I can't afford to turn off precompiled headers, as they speed up compilation alot).

    Thanks alot, just glad I wasnt the only one who has experienced this.

    - Dave



    : : hmmm. The only problem with removing the stdafx.h line is that it's not hte whole project that im compiling with 2 compilers, more then this is a shared file between projects (like a foundation file). So if I remove the stdafx.h include if I ever want to use this file in MSVC I'll get
    : :
    : : fatal error C1010: unexpected end of file while looking for precompiled header directive
    :
    : [blue]I don't know if this will work but I had this error one time and so I just turned off the precompiled headers. If you are using MSVC 6.0 go into Project->Settings. Next select your source file on the left. On the right side select the C/C++ tab and also select the Precompiled Headers under category. Last just select Not using Precompiled Headers. You will have to do the same for the release/debug version if it works.
    : [/blue]
    :
    : :
    : : Maybe my only solution is to include a file stdafx.h with all my projects regardless of whether or not im compiling with MSVC?
    : :
    : :
    :
    :

Sign In or Register to comment.