replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Trying to compile a C program with SCC
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trying to compile a C program with SCC

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri Sep 18, 2009 12:59 pm    Post subject: Trying to compile a C program with SCC Reply with quote

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 Sad

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 Very Happy 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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Fri Sep 18, 2009 2:25 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri Sep 18, 2009 2:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Fri Sep 18, 2009 5:27 pm    Post subject: Reply with quote

Try putting

#define TRILIBRARY

at the top of the file.

You could alternatively do this from the compiler command line.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri Sep 18, 2009 5:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri Sep 18, 2009 8:21 pm    Post subject: Reply with quote

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 Question
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat Sep 19, 2009 8:11 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Sat Sep 19, 2009 12:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Sun Sep 20, 2009 7:38 pm    Post subject: Reply with quote

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 Question

How can I give the inputline some initial value in the example program Question
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Mon Sep 21, 2009 7:43 am    Post subject: Found solution Reply with quote

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:
    #define NO_TIMER

    Remove
    Code:
    #ifndef TRILIBRARY
    char *readline();
    char *findfield();
    #endif /* not TRILIBRARY */
    and replace it with
    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
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri May 07, 2010 8:41 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group