Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Porting DOS source to GNU C - Backslashes

Posted on 2000-03-30
Medium Priority
Last Modified: 2010-04-15
I am trying to port a DOS program to Linux using the GNU C compiler.  I am stuck on the problem of directory slashes.  In our source we frequently have includes that are in a subdirectory of the main header directory.  For example:

#include <proto\lib\util.h>

Naturally, as the software was developed in the DOS/WIN world, we have used the backslash as our directory separator.

Now, when we try to compile with the GNU C compiler, it complains that it cannot find any of the include files that contain the backslashes (No such file or directory).   It can find include files that are in the top-level include directory (and therefore have no backslashes), so it's looking in the right place.

Is there a setting, switch or whatever that will allow GNU see to recognize these backslashes and find the files we are trying to include?  I tried usind the DIR_SEPARATOR define, but that didn't seem to help anything.
Question by:robworley
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Accepted Solution

imladris earned 630 total points
ID: 2670847
I think all would be well if you change them all to forward slashes. DOS will internally recognize a forward slash as a dir_separator. It's certainly not a legal character for a file name in DOS.

Author Comment

ID: 2670889
Adjusted points from 200 to 210

Author Comment

ID: 2670890
Well, that's a possibility.  Ultimately I'm talking about hundreds of files though and I'm trying to avoid a massive and tedious set of changes.  Is there any way to make the compiler recognize and honor the backslash?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 84

Expert Comment

ID: 2671139
You could write a script to change all the slashes in the #include directives.
Or you could copy /usr/include/proto/lib/util.h to /usr/include/proto\lib\util.h

Expert Comment

ID: 2671745
You can create soft links for all include paths in one common directory and include this directory in your compile time options using -I option.

e.g proto\lib\util.h can be a soft link as

proto\\lib\\util.h  -> actual path where util.h is stored in linux.
This can give you excellent abstraction to emulate the directoy env on linux machine without changing single line in your code.
May be you can put all this as a install shell script and run it on each new machine before you compile your programs on new machine.

Hope this helps.


Expert Comment

ID: 2671841
A suggestions:

In the main program, or some file that all file '#include', add this line:

#define \ /

That will replace all '\' with '/', and won't even screw up any math you might be doing.  I'm not sure that all cases are accounted for here, though.


Expert Comment

ID: 2672646
An ASCII game of warships might not like it...

Author Comment

ID: 2674428
Ufolk and bikeman: I could not get your solution/suggestion to work

ozo/imladris: I ended up writing a perl script to fix the files, so i guess I used a combination of your suggestions.  I don't know what's the best way to divide up the points.  

Maybe, one of you can post your answer as an answer here and I'll accept it.  And then I can open a dummy question so the other can get the points too?  Let me know how you want to work it out.
LVL 84

Expert Comment

ID: 2674443
macro name shall be an identifier
\ is not a legal macro name
LVL 12

Expert Comment

ID: 2676510
robworley: You can accept a comment as an answer--you should have a button which lets you do this.

Author Comment

ID: 2676818
This turned out to be the right answer, although a helpful suggestion from ozo was also implemented.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question