Solved

Porting DOS source to GNU C - Backslashes

Posted on 2000-03-30
11
365 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
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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now