Solved

Porting DOS source to GNU C - Backslashes

Posted on 2000-03-30
11
379 Views
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.
0
Comment
Question by:robworley
[X]
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
11 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 210 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.
0
 

Author Comment

by:robworley
ID: 2670889
Adjusted points from 200 to 210
0
 

Author Comment

by:robworley
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?
0
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

by:ozo
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
0
 
LVL 3

Expert Comment

by:ufolk123
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.

0
 
LVL 1

Expert Comment

by:the_bikeman
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.

the_bikeman
0
 
LVL 1

Expert Comment

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

Author Comment

by:robworley
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.
0
 
LVL 84

Expert Comment

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

Expert Comment

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

Author Comment

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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
logging Access violation 6 25
Understanding the meaning of Portability in Embedded System Programming 8 204
how to understand recursion 12 238
outlook office 365 8 172
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

752 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