Re: Porting code from Linux to Windows



In <55ab051f-1735-4f2c-bd4a-e2d5628284b8@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
lancer6238@xxxxxxxxx wrote:

Hi all,

I'm using Visual Studio .NET 2003, and I'm trying to port code I've
written and compiled/run successfully in Linux GCC to Windows.

I'm a newbie when using VS. I've created a new project,

I hope you created a "blank project", because otherwise VS tends to
set up some rather brain-damaged "helpful" source for you.

and added
all the .c and .h files I have into the project by Project -> Add
Existing Items, then chose all the .c and .h files.

Sounds good so far.

I'm not familiar with how exactly compilers and linkers etc work,
but is there a difference between how VS and gcc compile/link
#include files?

The specifics of the implementation will obviously vary, but standard
headers always work. Both GNU C and VS have ways to let you specify
paths for your own headers, but the easiest way for basic projects is
simply to put your headers in the project directory, upon which a
simple #include "myhdr.h" should work just fine.

My habit of programming in Linux has been to have
one main.c file, and #include all other .h or .c files that I need.

Oooooh bad idea. Right for .h, but wrong for .c - what you ought to do
(on both gcc and VS) is compile the C files separately, and link them
at the end. This may cause you some teething troubles (which are
easily resolved by consultation!), but it's the Right Way and will
save you trouble in the long run.

Then I would only compile the main.c file. But in VS, it seems as if
the #include files are not "seen" by the program, because I'm
getting errors that tell me certain structures or variables were not
declared, even though they are in my user-defined header files.

Without the specifics, it's hard to comment sensibly. Are you getting
messages along the lines of "can't find header"? If not, then that
isn't your problem - you have a C problem (quite possibly related to
the fact that you're #including the world and his dog) which we can
help with if we can see the code.

I'm also getting errors like DIR is an undeclared identifier. I've
included , so why can't it recognize DIR?

That's a POSIX thing, not a C thing, and Visual Studio is under no
obligation to support it. (Last I checked, it doesn't, but it's
conceivable it has been added. Look it up on MSDN.) Of course VS has
a way of reading directories, but the details are rather different
from what you're used to. Although it's off-topic here (and thus any
answers you get along those lines should be viewed with suspicion),
it's bang on topic in comp.os.ms-windows.programmer.win32 where some
serious Windows experts hang out. But the following link may give you
some clue as to what's involved in reading directories in Win32
(remember, treat this link with suspicion!):

http://www.cpax.org.uk/prg/windows/dirparse.c

But your first step should be to understand how a basic multi-file
project works in Visual Studio.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
.



Relevant Pages

  • compiling iso c++ code in Visual Studio environment
    ... My code compiles well with gcc on linux and OS X, but now I have to run it at work, and my only choice is Visual Studio .Net 2003 environment on windows, which I had never used before. ... Also, it gives a bizarre error that there is something wrong with the stdio headers in my files-- except that I don't use stdio, I use iostream. ... I was wondering if anyone experienced with it can give me a hint or two about compiling portable code with it ...
    (microsoft.public.vc.language)
  • Re: compiling iso c++ code in Visual Studio environment
    ... My code compiles well with gcc on linux and OS X, but now I have to run it at work, and my only choice is Visual Studio .Net 2003 environment on windows, which I had never used before. ... Also, it gives a bizarre error that there is something wrong with the stdio headers in my files-- except that I don't use stdio, I use iostream. ...
    (microsoft.public.vc.language)
  • Re: slime, debian(testing, 2.6.8), sbcl(0.9.16)
    ... I think you need to install GCC and kernel headers. ... What I don't understand is what GCC has to do with SBCL in this case. ...
    (comp.lang.lisp)
  • Re: Porting code from Linux to Windows
    ... written and compiled/run successfully in Linux GCC to Windows. ... The way Visual Studio works is essentially by automatically creating a makefile for you. ...
    (microsoft.public.vstudio.general)
  • Re: Atlsmtpconnection.h
    ... It is my understanding that there is no ATL support with the Visual Studio ... 2005 Express package, so it doesn't surprise me that the ATL*.h headers are ... emails at the socket level isn't hard to program. ...
    (microsoft.public.vc.atl)