Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-01-2007, 12:32 PM   #1 (permalink)
The Linux Man !
 
paragkalra's Avatar
 
Join Date: Jan 2006
Location: Nagpur, Maharashtra, India
Posts: 217
Default GCC vs VISUAL STUDIO

I need your help very urgently.......

Actually my HOD (head of department) is doing PHD....

He has a .c file which can be successfully compiled on LINUX using gcc....

I myself have successfully compiled it on REDHAT

Now he wants to compile the same program on Windows using VISUAL STUDIO...

Is there any way out to solve this problem...

Actually its throwing some error...

Actually I have very little knowledge oF MICROSOFT PRODUCTS ....

Please kindly try to solve my problem as early as possible.....It's very urgent....

Here's the code:
/* cap2d.c
-------
This program takes arguments D and k, the parameters for the
Wierstraus-Mandelbrot (W-M) function. A two-dimensional unit
surface is generated with fract2d(), defined in wm.c. A second
flat surface is placed at a distance CAP_D above the first. Using
the method of finite differences, Laplace's equation is found, and
the capacitance (in the form of electrical flux per unit area) is
written to the file named in OUTFILE as Matlab commands.

As the program runs, it prints the iteration count and the finite
difference tolerance to stdout.

To compile:

gcc capacitance.c wm2d.c -lm -O2 -o ./cap2d

To run:

./cap2d D k

(where 1 < D < 2 and |1-k| < |1-D|.)\n"
*/

#include "wm2d.h"

// For convenience, try keeping NPTS = 1.0 / SCALE
#define NPTS 100 // Surfaces have NPTS x NPTS nodes
#define SCALE 0.01 // Separation of each node

#define L_OS 0.9 // Undershoot factor. See iterate(), below
#define L_IT 50000 // Number of finite difference iterations

#define CAP_D 2.0 // Mean separation of the two surfaces
#define CAP_V 1.0 // Surfaces have potential +/- CAP_V

#define OUTFILE "temp.m"
#define USAGE "Incorrect arguments. Usage: cap2d D k"

/* Macro for periodic boundary conditions, called by iterate(). */
#define WRAP(a) (((a) + NPTS) % NPTS)

/* Function prototypes. Watch out for use of both floats and doubles.
The array phi[][][] uses floats to speed up iterate(), while the
matrix inversion in fract2d() needs doubles to avoid overflow. */
float laplace (double **zlo, double **zhi);
inline float iterate(float ***phi1, float ***phi2, int **surfmin, int **surfmax);
void outfile(double D, float flux);
void lfree (float ***phi1, float ***phi2, int **surfmin, int **surfmax);


int main (int argc, char **argv) {

int i, j;
float flux;
double wm_H, wm_k, **zlo, **zhi;

if (argc == 3) {
wm_H = 2.0 - strtod(argv[1], NULL);
wm_k = strtod(argv[2], NULL);
} else
error(1, 0, USAGE);

/* Each surface is stored in an NPTS x NPTS 2-D array. The array
indices (times SCALE) are the x and y coordinates. The array
contents are the z-coordinates. */

zlo = (double **)xmalloc(NPTS * sizeof(double *));
zhi = (double **)xmalloc(NPTS * sizeof(double *));
for (i = 0; i < NPTS; i++) {
zlo[i] = (double *)xmalloc(NPTS * sizeof(double));
zhi[i] = (double *)xmalloc(NPTS * sizeof(double));
}

/* Fill zlo using the W-M function, with mean zero. */
fract2d(zlo, wm_H, wm_k, NPTS, SCALE);

/* Fill zhi with a simple flat surface z = CAP_D. */
for (i = 0; i < NPTS; i++)
for (j = 0; j < NPTS; j++)
zhi[i][j] = CAP_D;

flux = laplace (zlo, zhi);
outfile(2.0-wm_H, flux);

freezpt(zlo, NPTS);
freezpt(zhi, NPTS);

exit(0);
}


/* This function creates a 3-D array representing the potential in the
cavity between the surfaces. Using the finite difference method, we
solve Laplace's equation for the cavity.

The function returns the flux, which is
flux = (sum) E . dA
= A * (sum) dE/dz
= 1 * ((sum)dE) / SCALE

Note that the capacitance is simply
C = flux / ( CAP_V * epsilon_0) */
float laplace (double **zlo, double **zhi) {

int i, j, k, m, n, nz;
float tmp;
double zmin, zmax;

int **surfmin = xmalloc(NPTS * sizeof (int *));
int **surfmax = xmalloc(NPTS * sizeof (int *));

float ***phi1 = xmalloc(NPTS * sizeof (float **));
float ***phi2 = xmalloc(NPTS * sizeof (float **));
float ***phi3;

zmin = HUGE_VAL;
zmax = 0.0;
for (i = 0; i < NPTS; i++)
for (j = 0; j < NPTS; j++) {
if (zmin > zlo[i][j]) zmin = zlo[i][j];
if (zmax < zhi[i][j]) zmax = zhi[i][j];
}

nz = 1 + (int)((zmax - zmin)/SCALE);

for (i = 0; i < NPTS; i++) {
surfmin[i] = (int *)xmalloc(NPTS * sizeof (int));
surfmax[i] = (int *)xmalloc(NPTS * sizeof (int));
phi1[i] = (float **)xmalloc(NPTS * sizeof (float *));
phi2[i] = (float **)xmalloc(NPTS * sizeof (float *));

for (j = 0; j < NPTS; j++) {
phi1[i][j] = (float *)xmalloc(nz * sizeof(float));
phi2[i][j] = (float *)xmalloc(nz * sizeof(float));
}
}

for (i = 0; i < NPTS; i++) {
for (j = 0; j < NPTS; j++) {

/* surfmin and surfmax contain the index for the lower and upper
surfaces respectively. For example, phi[i][j][surfmin[i][j]]
gives the potential of the lower surface. */
surfmin[i][j] = (int)((zlo[i][j]-zmin)/SCALE);
surfmax[i][j] = (int)((zhi[i][j]-zmin)/SCALE);

if (surfmin[i][j] > surfmax[i][j])
error(1, 0, "Surfaces of capacitor meet.");

/* The nodes outside the cavity (including the surface nodes)
are maintained at +/- CAP_V. */
for (m = 0; m <= surfmin[i][j]; m++)
*(phi1[i][j] + m) = *(phi2[i][j] + m) = - CAP_V;

for (n = nz - 1; n >= surfmax[i][j]; n--)
*(phi1[i][j] + n) = *(phi2[i][j] + n) = CAP_V;

/* As an initial guess, we let the potential drop linearly from
the lowest point (zmin) to the highest point (zmax). */
tmp = 1.0 / (n - m);
for (k = m + 1; k < n; k++)
phi1[i][j][k] = 2 * CAP_V * (k - m) * tmp - CAP_V;
}
}

/* Perform finite difference iterations. tmp is the
"badness-of-fit," which should converge to zero. If it starts
blowing up or oscillating wildly, decrease L_OS. */
for (i = 0; i < L_IT; i++) {
tmp = iterate(phi1, phi2, surfmin, surfmax);
phi3 = phi1; phi1 = phi2; phi2 = phi3;
printf ("\r[%5d] %.2f ", i, tmp);
fflush(stdout);
}
printf("\n");

/* Compute and return the flux. */
tmp = 0.0;
k = nz - 5;
for (i=0; i < NPTS; i++)
for (j=0; j < NPTS; j++)
if (k < surfmin[i][j] || k > surfmax[i][j])
error(1, 0, "Surfaces of capacitor meet.");
else
tmp += (phi1[i][j][k+1] - phi1[i][j][k]);

lfree(phi1, phi2, surfmin, surfmax);
return (tmp * SCALE);
}


/* This function performs the finite difference step:

phi_{n+1} (x,y,z) = phi_{n} (x,y,z) + L_OS * A(x,y,z)

where L_OS is the (under/over)relaxation and

A(x,y,z) = 1/6 * ( phi_{n} (x+h, y, z) + phi_{n} (x-h, y, z)
+ phi_{n} (x, y+h, z) + phi_{n} (x, y-h, z)
+ phi_{n} (x, y, z+h) + phi_{n} (x, y, z-h) )
- phi_{n} (x,y,z)

phi_{n} is stored in phi1. The function stores phi_{n+1} in phi2. */

inline float iterate(float ***phi1, float ***phi2, int **surfmin, int **surfmax) {

int i, j, k;
float tmp, tol = 0.0;

for (i = 0; i < NPTS; i++)
for (j = 0; j < NPTS; j++)
for (k = surfmin[i][j] + 1; k < surfmax[i][j]; k++) {
tmp = phi1[i][j][k-1] + phi1[i][j][k+1];
tmp += phi1[WRAP(i-1)][j][k] + phi1[WRAP(i+1)][j][k];
tmp += phi1[i][WRAP(j-1)][k] + phi1[i][WRAP(j+1)][k];
tmp *= 0.1666667;
tmp -= phi1[i][j][k];
tol += tmp;
phi2[i][j][k] = phi1[i][j][k] + L_OS * tmp;
}
return tol;
}

void outfile(double D, float flux) {

FILE *out = fopen(OUTFILE, "a");

fprintf(out, "D = %f : ", D);
fprintf(out, "flux = %f\n", flux);

fclose(out);
}

/* Frees memory allocated in laplace(). */
void lfree (float ***phi1, float ***phi2, int **surfmin, int **surfmax) {

int i, j;
for (i = 0; i < NPTS; i++) {
for (j = 0; j < NPTS; j++) {
free(phi1[i][j]);
free(phi2[i][j]);
}
free(phi1[i]);
free(phi2[i]);
free(surfmin[i]);
free(surfmax[i]);
}
free(phi1);
free(phi2);
free(surfmin);
free(surfmax);
}


HERE's the ERROR:
------ Build started: Project: cap2d, Configuration: Debug Win32 ------
Compiling...
cap2d.c
e:\d drive backup\parag\final_year_project\code\wm2d.h(2) : fatal error C1083: Cannot open include file: 'math.h': No such file or directory
Build log was saved at "file://e:\D drive backup\parag\final_year_project\code\Debug\BuildLo g.htm"
cap2d - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
__________________
Parag.A.Kalra, The Linux Man
http://www.paragkalra.com/
In this world without WALLS and GATES who need WINDOWS! USE LINUX! STOP PIRACY! GO OPEN SOURCE!
paragkalra is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-01-2007, 03:04 PM   #2 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: GCC vs VISUAL STUDIO

I am very much of a noob at programming but the error message explicitly shows that math.h file is missing. math.h is called by wm2d.h so check that code and correct the error.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 05-01-2007, 03:50 PM   #3 (permalink)
Google Bot
 
Pathik's Avatar
 
Join Date: Aug 2005
Posts: 9,751
Default Re: GCC vs VISUAL STUDIO

hv u created the wm2d.h library urself????? n y dont u include <math.h> as well
Pathik is offline  
Old 07-01-2007, 09:54 AM   #4 (permalink)
In The Zone
 
morpheusv6's Avatar
 
Join Date: Dec 2006
Location: Bangalore
Posts: 215
Question Re: GCC vs VISUAL STUDIO

Can GCC run on the windows platform(windows XP more specifically) or do I have to download linux for that( please recommend if yes(Fedora Core 6 or Ubuntu or any other))?
I am currently using Dev C++ and MS VC++ Express Edition 2005.

But a programming competion I attended a few months back was based on GCC.

Is there any syntax difference between those program which are compiled in MS VC++ and GCC?
Also recommend a good book to learn GCC, I already have knowledge of C and C++.
__________________
Deven
morpheusv6 is offline  
Old 07-01-2007, 10:40 AM   #5 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: GCC vs VISUAL STUDIO

Dev C++ uses MingW which stans for minimalistic gnu for windows, it has windows port for gcc. So, you are using gcc.
That's as much as I know.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 07-01-2007, 10:47 AM   #6 (permalink)
FooBar Guy
 
GNUrag's Avatar
 
Join Date: Jun 2004
Location: GNUmbai
Posts: 1,245
Default Re: GCC vs VISUAL STUDIO

Search where is the include file named "math.h" in your VS.Net++ installation, note that path, and give it while compiling.

With gcc/turboc++ its given with the -I/path/to/math.h parameter.

Mostly there should be a GUI interface where you can enter what all directories the preprocessor needs to look at for include libraries.
__________________
- --
http://www.MovieAB.com - A tiny movie mashup!
GNUrag is offline  
Old 08-01-2007, 02:47 PM   #7 (permalink)
"The RaCaLaNGeL"©
 
romeo_8693's Avatar
 
Join Date: Dec 2005
Location: Goa/Pune
Posts: 389
Default Re: GCC vs VISUAL STUDIO

i read sumwhere that linux source codes can be compiled in windows environment using cygwin!dnt know wats the proc tho....run a search u shud get it..
__________________
Without sorrows happiness would be boring!
romeo_8693 is offline  
Old 08-01-2007, 04:37 PM   #8 (permalink)
The Lord of Death
 
Yamaraj's Avatar
 
Join Date: May 2005
Location: यमलोक
Posts: 253
Default Re: GCC vs VISUAL STUDIO

Quote:
Originally Posted by morpheusv6
Can GCC run on the windows platform(windows XP more specifically) or do I have to download linux for that( please recommend if yes(Fedora Core 6 or Ubuntu or any other))?
I am currently using Dev C++ and MS VC++ Express Edition 2005.

But a programming competion I attended a few months back was based on GCC.

Is there any syntax difference between those program which are compiled in MS VC++ and GCC?
Also recommend a good book to learn GCC, I already have knowledge of C and C++.
1. Yes, GCC has a Win32 port that runs on Windows. MinGW, as noted by tech_your_future, is available; but even the latest version (candidate release) comes with GCC-3.4.5. I compile my own GCC, binutils, win32api and mingw-runtime, which in turn is used to build and distribute ntemacs - http://ntemacs.sourceforge.net
I have GCC-4.1.1, binutils-2.17 and other latest toolchain for Win32 - built myself of course. If I get enough requests, I may even upload it someplace.

2. GCC will compile all standard C and C++ code, provided they comply with the ANSI/ISO standards. It should be noted, however, that C99 is still not completely supported by any compiler[*]. Same goes for C++; very few compilers support the entire C++98 ISO standard.

3. I recommend official GNU manuals for GCC. You may also want to look at "An Introduction to GCC" and "Using GCC". http://www.network-theory.co.uk/docs/gccintro/ Another good book is "Definitive Guide to GCC".

[*] - Comeau compiler is probably the only exception.

Last edited by Yamaraj; 09-01-2007 at 11:16 PM.
Yamaraj is offline  
Old 08-01-2007, 06:24 PM   #9 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: GCC vs VISUAL STUDIO

well there IS NO math.h in standard C++ , it is in C so you should use :
Code:
#include<cmath>
instead of :
Code:
#include<math.h>
Quote:
Originally Posted by morpheusv6
Can GCC run on the windows platform(windows XP more specifically) or do I have to download linux for that( please recommend if yes(Fedora Core 6 or Ubuntu or any other))?
I am currently using Dev C++ and MS VC++ Express Edition 2005.

But a programming competion I attended a few months back was based on GCC.

Is there any syntax difference between those program which are compiled in MS VC++ and GCC?
Also recommend a good book to learn GCC, I already have knowledge of C and C++.
hey made STANDARD C++ programs will compile on both the compilers perfectly , it is the depricated libraries that pose the problems , most ppl learn C in the name of C++ using OLD style headers , etc .
__________________
There are 10 types of people in the world: those who understand binary and those who do not.

Last edited by Zeeshan Quireshi; 08-01-2007 at 06:41 PM.
Zeeshan Quireshi is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 05:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2