Help: include statement for win32 and linux

Hi,

I have to write a small C++ code that runs on window and linux. Actually I am writing a sequence code for MRI and the scanner uses both window and linux to complete the data acquisition.

I am having problem with include statement #ifdef WIN32 ...

The statement that works fine:
==========================================
#include "stdafx.h"
#ifdef WIN32
#include "stdafx.h"
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
#include "test.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
==========================================

However, since stdafx.h is only for visual studio, I want to write this as:
==========================================
#ifdef WIN32
#include "stdafx.h"
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
//#include "test.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
==========================================
However that throws error.

Please help.

Regards,
DK
Yeah, too bad you don't show the actual error that you get. That's always good information.

I am going to guess and say that Visual Studio complains because the pre-compiled header is not the first thing in the CPP file.

I don't program for Linux, but I would try one of two approaches:

1. Simply deactivate the use of the pre-compiled header in the project options.
2. Have a blank stdafx.h file in Linux as well so the linux compiler doesn't complain.
Topic archived. No new replies allowed.