-1

I have project developed in c on windows machine using Microsoft Visual Studio. The project is successfully compiled and run on windows but when trying to compile source code(.cpp, .h) on linux server it throws errors like

Errors:

In file included from
warning: `#pragma once' is obsolete
SDKDDKVer.h: No such file or directory

The command used to compile *.cpp file is

gcc-2.95 -c -g -O2 -ffloat-store -Wall -Wpointer-arith\ -Wbad-function-cast -Wwrite-strings -Wstrict-prototypes\ -Wmissing-declarations -Werror -ftemplate-depth-25 -Iinclude file1.cpp

searched online but could not find any direct solution to the problem. On few websites they have suggested to use Cygwin but my task is one time activity so not sure if it is really required to setup Cygwin on my pc. I am not sure what the errors above mean(as I am new to c).

Let me know if there is any place/websites that lists the changes required while moving from c programs from windows to linux.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
  • 5
    Your compiler is very ***very*** old! It was released in 1999. – Some programmer dude Sep 14 '17 at 12:22
  • 1
    Also, you generally can't compile C code in both Windows and Linux without some porting or using a compatibility framework (like MinGW or WINE). – Some programmer dude Sep 14 '17 at 12:23
  • @Someprogrammerdude what? As long as you only use standard functionality and cross-platform libraries, there's no porting of your own code to be done. That's actually the primary goal of C. – Quentin Sep 14 '17 at 12:25
  • 1
    You name your C files `.cpp`? – Klas Lindbäck Sep 14 '17 at 12:26
  • @Quentin Well, `SDKDDKVer.h` is definitely not a standard header file, so it's safe to assume the program uses some Windows-specific code. Depending on what the OP is doing then using [WINE](https://www.winehq.org/) might work. – Some programmer dude Sep 14 '17 at 12:26
  • The advice about using Cygwin is completely wrong. [Cygwin](http://cygwin.org/) is a large set of Linux command line tools that were compiled for Windows and run on Windows on top of an emulation layer (provided by `cygwin1.dll`, that is included in Cygwin.) – axiac Sep 14 '17 at 12:27
  • 1
    GCC compiler version 2.95? Are you sure you're using something almost 20 years old? – iBug Sep 14 '17 at 12:28
  • @Someprogrammerdude oh, that's from a microsoft SDK then. Fair enough, didn't think of checking that. – Quentin Sep 14 '17 at 12:28
  • 1
    first update to a newer version of gcc, which should get rid of the `#pragma once` error. SDKDDKver.h is a window specific header, there is no Linux equivalent, you will need to remove it. I suspect that you will get many more errors along these lines. – thurizas Sep 14 '17 at 12:28
  • What is your project about? Does it have some GUI? Then consider using some cross-platform GUI widget toolkit (e.g. [Qt](http://qt.io/) or [GTK](http://gtk.org/)...). Otherwise, use a framework like [POCO](http://pocoproject.org/)... – Basile Starynkevitch Sep 14 '17 at 12:33
  • Apparently you compile C++, not C. They are different languages! – too honest for this site Sep 14 '17 at 13:12

1 Answers1

5

There is no recipe for converting a codebase from an environment to another.

Writing good code is hard. Unfortunately, writing good and portable code is even harder.

Basically, you need at all time to be aware of what is available on what platform, what is available on only one platform and what are the equivalents on other platforms.

It is useful to use standard libraries and libraries which are known to be available on multiple platforms (such as Boost).

It is hard to give more specific advice since this is a quite broad topic. What I can say is that the error you've shown is about a windows-specific header `SDKDDKVer.h, which you have to replace somehow. This means to find equivalents for whatever you use from that header.

Paul92
  • 8,827
  • 1
  • 23
  • 37