View previous topic :: View next topic |
Author |
Message |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Sep 18, 2009 12:59 pm Post subject: Trying to compile a C program with SCC |
|
|
Hi,
I have no experience with the Silverfrost C++ compiler. However, I found a very usefull mesh generator (for FEM) written in C that I would really like to use in our software. According to the author only standard C was used from which I suppose the Silverfrost C++ should be able to compile it. As usuall my fisrt attempt did not succeed
Since my lack of experience with C I do not now what to do with in oder to compile the C code (triangle.c) found at: http://www.cs.cmu.edu/~quake/triangle.html.
The author suggests the following easy way to compile:
Quote: | Alternatively, the files are usually easy to compile without a makefile: cc -O -o triangle triangle.c -lm |
Unfortunatley the code is to long to add in the Forum. I would however apprceiate it if anyone with experience using the Silverfrost C++ compiler could take a quick look at it. Once I can compile the code, I would be able the figure out the rest.
Regards
Jacques |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Fri Sep 18, 2009 2:25 pm Post subject: |
|
|
If it is standard C then there is a good chance that SCC will compile it SCC has not been touched for a while and the C standard is progressing so it is possible that SCC might not be able to handle recent additions to the standard.
Try putting the files into a Plato project and do a build.
What do the error messages look like? |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Sep 18, 2009 2:36 pm Post subject: |
|
|
Hi Paul,
the error message that I get is as follows:
Code: |
H:\FTN95\TRIANGLE\TRIANGLE.C(11184) : error 140 - Function 'readline' requires no arguments
H:\FTN95\TRIANGLE\TRIANGLE.C(11184) : fatal 233 - Compilation abandoned
|
In the code itself the line where the compiler gives an error looks like:
Code: |
/* Read number of triangles, number of vertices per triangle, and */
/* number of triangle attributes from .ele file. */
stringptr = readline(inputline, elefile, elefilename);
m->inelements = (int) strtol(stringptr, &stringptr, 0);
stringptr = findfield(stringptr);
|
At the top of the source file readline seems to be defined like:
Code: |
/* A few forward declarations. */
#ifndef TRILIBRARY
char *readline();
char *findfield();
#endif /* not TRILIBRARY */
|
If I remove the line then I get the following:
Code: |
H:\FTN95\TRIANGLE\TRIANGLE.C(11088) : fatal 177 - End of source file while processing this #if, #ifdef or #ifndef
|
Jacques |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Fri Sep 18, 2009 5:27 pm Post subject: |
|
|
Try putting
#define TRILIBRARY
at the top of the file.
You could alternatively do this from the compiler command line. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Sep 18, 2009 5:59 pm Post subject: |
|
|
Hi Paul,
I included both the #define NO_TIMER and #define TRILIBRARY switches and it compiled. From this I obtained the .lib and .obj files.
This will also be my first attempt to make use of the mixed language capability.
Thanks for looking at the code!
Regards
Jacques |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Sep 18, 2009 8:21 pm Post subject: |
|
|
The file triangle.c compiled with success resulting in a triangle.lib file. If my understanding is correct then I must add this as a reference when I write a simple driver progrom for the library. Is this correct?
I tried this with the accompaning example but then I get the following error:
Quote: | H:\FTN95\TRICALL\TRICALL.C(213) : warning 215 - The result of this statement is not used
H:\FTN95\TRICALL\TRICALL.C(241) : error 140 - Function 'triangulate' requires no arguments
H:\FTN95\TRICALL\TRICALL.C(241) : warning 215 - The result of this statement is not used
*** Compilation failed |
This must be somehow related to the following code:
Code: | #ifdef ANSI_DECLARATORS
void triangulate(char *, struct triangulateio *, struct triangulateio *,
struct triangulateio *);
void trifree(VOID *memptr);
#else /* not ANSI_DECLARATORS */
void triangulate();
void trifree();
#endif /* not ANSI_DECLARATORS */ |
Again I must mention that I have no C experience. If I could only get the code to compile I would be able to test the rest. I assume that the above code needs something like Code: | #define ANSI_DECLARATORS | somewhere. However there is no instruction like this. Is this needed at all  |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sat Sep 19, 2009 8:11 am Post subject: |
|
|
Yes you probably need the #define.
These usually appear on the compiler command line rather than in the code and they are used to make the code accessible to various compilers.
To be realistic you will need to learn a little bit of C before making progress.
.obj files can be combined (using SLINK) into static libraries (.lin) or into dynamic libraries (.dll). They are different and are used in different ways. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Sat Sep 19, 2009 12:45 pm Post subject: |
|
|
You are correct about learning a bit C. It is my intention to do so. Therefore I got the source of a usefull application of which I have the executable.
Since I have a Silverfrost compiler I believe that the Silverfrost forum must be the best place to ask for help.
Somehow it compiles. However, it is really unuasual that I cannot compile the file to get an executable. It works for a .lib. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Sun Sep 20, 2009 7:38 pm Post subject: |
|
|
I followed your advise and work through a C tutorial (http://www.cprogramming.com/tutorial.html#ctutorial). This is in many cases similar to Matlab.
Returning to my problem: The code has two main switches 1) TRILIBRARY and 2) ANSI_DECLARATORS which can be used like this:
Code: | #ifdef ANSI_DECLARATORS
....
#else
...
#endif | Furthermore, I took the function where the compiler gives an error and made a single C program with the following code: Code: | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INPUTLINESIZE 1024
char *readline(char *string, FILE *infile, char *infilename);
void triexit(int status);
int main(){
FILE *elefile;
char *elefilename;
char inputline[INPUTLINESIZE];
char *stringptr;
printf("Try only the readline subroutine\n");
stringptr = readline(inputline, elefile, elefilename);
getchar();
return 0;
}
char *readline(char *string, FILE *infile, char *infilename)
{
char *result;
/* Search for something that looks like a number. */
do {
result = fgets(string, INPUTLINESIZE, infile);
if (result == (char *) NULL) {
printf(" Error: Unexpected end of file in %s.\n", infilename);
triexit(1);
}
/* Skip anything that doesn't look like a number, a comment, */
/* or the end of a line. */
while ((*result != '\0') && (*result != '#')
&& (*result != '.') && (*result != '+') && (*result != '-')
&& ((*result < '0') || (*result > '9'))) {
result++;
}
/* If it's a comment or end of line, read another line and try again. */
} while ((*result == '#') || (*result == '\0'));
return result;
}
void triexit(int status)
{
exit(status);
} |
My Questions:
The original source code offer two options to define a function, i.e. the standard ANSI C convention and some non standard ANSI C convension (at least that is how I understand it). To compile with SCC I assume the best option would be standard ANSI C. Is that correct
How can I give the inputline some initial value in the example program  |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Sep 21, 2009 7:43 am Post subject: Found solution |
|
|
I would like to close off this discussion with the following solution I found from http://www.triplexware.huckfinn.de/triapi_eng.html. The author experienced the same error.
In order to compile triangle.c successful with SCC the following needs to be done:
Code: | #ifndef TRILIBRARY
char *readline();
char *findfield();
#endif /* not TRILIBRARY */ | Code: | char *readline(char *string,FILE *infile,char *infilename);
char *findfield(char *string); |
In doing so compiling with SCC results in a valid executable. The few tests I did seem to be fine. The other questions I have are related to mixed programing. I will address these question under a new topic (if necessary). |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri May 07, 2010 8:41 am Post subject: |
|
|
Using Triangle (C-written 2-D FEM mesher) with the Silverfrost C/C++ compiler is no problem. In the meanwhile I compiled the mesher as a static library (.lib file) to include it in a Fortran program. A very simple viewer (with some help from the Forum) in Clearwin can display the results. A typical result is shown below. The viewer (TPlot - Triangle Plot) is very simple and I hope to expand it somewhat. Moreover, my dream is to develop a magnetostatic FEA package only using Silverfrost.
 |
|
Back to top |
|
 |
|