c++linuxwindowsvisual-studio

Visual studio C++: How to make parts of code not be seen by the windows compiler?


So jenerally I have small C++ project based on OpenSource crossplatform libs. So it probably would compile under linux. So I hited the point when I need to implement some defenatly platform specific class functions.

I have a class header with all functions declarations and cpp file with realisations. So first: how to declare my platform specific functions in header so when I'll try to compile under linux it will not try to compile windows specific ones... and when on windows compiler will not try to compile linux functions include headers etc.

So for windows I need some how wrap such super specific functions

HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
void DisplayDeviceInformation(IEnumMoniker *pEnum)

And some headers

#include <windows.h>
#include <dshow.h>

#pragma comment(lib, "strmiids")

While for linux I have such headers

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev.h>

And I have function with name of void PrintCamerasList() which I wanna have one for bouth platfrms realisations for which I have seprate.

I hope you see what I need. So generally I need some example using my functions or once you can invent - let your imagination flow!)

So why do I need it all - I am creating some console app using OpenCV and I need to list user cameras names. OpenCV cannot do this on its own. so I asked how to do it for bouth platforms of my intrest - windows and linux


Solution

  • Take a look at http://predef.sourceforge.net/ for an extensive list of pre-defined macros various compilers provide to distinguish between operating systems, compilers, and processor architectures. They will allow you to distinguish between more than just Win32 and Linux if necessary.