LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2009, 06:56 AM   #1
SuperNomad
LQ Newbie
 
Registered: Feb 2009
Posts: 7

Rep: Reputation: 0
PGPlot in 'C' compiling: undefined reference to `MAIN_` (ubuntu 8.10)


I am trying to compile a program written in 'C' to draw a fractal using PGPlot, but I can't get it working.

This is the code I'm trying to compile:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cpgplot.h>

/* ---------------------------------------------------------------------
* Plotting Julia set by the Level Set Method
*
* Usage on ULTRA:
* source /home/z/zrw/under/pgplot_c (set up just once a session)
* cc fractal1.c `cpgplot_link` -o fractal1 (to compile program)
*
* R. Willingale 2006-Feb-09
*----------------------------------------------------------------------
*/

/* maximum number of iterations for each point */
#define NITER 10000
/* number of columns in image */
#define NCOLS 800
/* number of rows in image */
#define NROWS 400

/* function to set colour table in pgplot */
void cpgsetlut();

int main

{
float rmin = -2.0, rmax = 2.0;
float pix=(rmax-rmin)/NCOLS;
float imin = -1.0, imax = imin+NROWS*pix;
double rtarget=1.e8, cr=-0.74543, ci=0.11301;
int i,j,ni;
float arr[NROWS*NCOLS], tr[6], zmin, zmax;
double rs,vr,vi,sr,si,tt;
zmin=NITER;
zmax=0.0;
for(i=0; i<NROWS; i++) {
si=imin+pix*(i+0.5);
for(j=0; j<NCOLS; j++) {
sr=rmin+pix*(j+0.5);
vr=sr;
vi=si;
rs=vr*vr+vi*vi;
ni=0;
while((rs<rtarget)&&(ni<NITER)) {

/* 4 lines to calculate the quadratic mapping missing */

tt = vr ;
vr = (vr*vr - vi*vi) + cr ;
vi = (2*tt*vi) + ci ;
rs = vr*vr + vi*vi ;

ni++;
}
tt=ni; tt=log(tt);
arr[j+i*NCOLS]=tt;
if(zmax<tt)
zmax=tt;
if(zmin>tt)
zmin=tt;
}
}
cpgbeg(0, "?", 1, 1);
cpgsetlut();
cpgwnad(rmin,rmax,imin,imax);
tr[0]=rmin-0.5*pix; tr[1]=pix; tr[2]=0.0;
tr[3]=imin-0.5*pix; tr[4]=0.0; tr[5]=pix;
cpgimag(arr,NCOLS,NROWS,1,NCOLS,1,NROWS,zmin,zmax,tr);
cpgbox("BCTN", 0.0, 0, "BCNST", 0.0, 0);
cpglab("real axis","imaginary axis","Julia set by the Level Set Method");
cpgend();
}

void cpgsetlut()
{
int i,icmin,icmax,n1,n2;
float dd, rcol,gcol,bcol;
cpgqcir(&icmin,&icmax);
dd=3.0/(icmax-icmin);
n1=icmin+(icmax-icmin)/3;
n2=icmin+((icmax-icmin)*2)/3;
for(i=icmin; i<icmax+1; i++) {
if(i<=n1) {
rcol=(i-icmin)*dd; gcol=0.0; bcol=0.0;
} else if((i>n1)&&(i<=n2)) {
rcol=1.0; gcol=(i-n1)*dd; bcol=0.0;
} else if(i>n2) {
rcol=1.0; gcol=1.0; bcol=(i-n2)*dd;
}
if(rcol>1.0) rcol=1.0; if(gcol>1.0) gcol=1.0; if(bcol>1.0) bcol=1.0;
cpgscr(i,rcol,gcol,bcol);
}
}

To compile the program I am using the command:

$ gcc -c fractal1original.c
$ f77 -o fractal1original fractal1original.o -lcpgplot -lpgplot -lgcc -lm

but it returns the error: /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libf2c.so: undefined reference to `MAIN__'

Really not sure how to go about solving this, the internet suggest its a problem linking the C libraries to the Fortran libraries.

Any help would be greatly appreciated.
 
Old 02-25-2009, 08:53 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Instead of
Code:
int main
you probably want
Code:
int main(void)
 
Old 02-25-2009, 09:21 AM   #3
SuperNomad
LQ Newbie
 
Registered: Feb 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for the quick reply, but unfortunately that didn't work, I still get the same error.
 
Old 02-28-2009, 12:33 PM   #4
SuperNomad
LQ Newbie
 
Registered: Feb 2009
Posts: 7

Original Poster
Rep: Reputation: 0
I've used a guide to try and get pgplot to work and I've had some success. I can run the precompiled demo that comes with pgplot however when I come to compile my own code I get a load errors about gfortran.

The guide I'm using can be found here:

http://www.dur.ac.uk/physics.astrolab/ppgplot.html

and here are the errors:

rob@rob-laptop:~/Desktop$ gcc -c fractal1original.crob@rob-laptop:~/Desktop$ f77 -o fractal1original fractal1original.o -lcpgplot -lpgplot -lX11 -lgcc -lm
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_concat_string'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_write_done'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_transfer_integer'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_read'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_inquire'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_stop_numeric'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_pow_i4_i4'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_write'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_getenv'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_read_done'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_runtime_error'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_compare_string'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_transfer_array'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_string_index'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_close'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_st_open'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_transfer_character'
/usr/local/lib/libpgplot.so: undefined reference to `_gfortran_os_error'
collect2: ld returned 1 exit status

I've also added: int MAIN__() {return 0;} to the code.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
undefined reference to `yywrap' compiling PAM Mahonri Debian 5 12-30-2011 06:00 PM
compiling linux 2.6.19.2 failed with "undefined reference to s3c2410_pm_drvinit" cucmi Linux - Hardware 2 08-18-2008 10:21 PM
Undefined errno reference while compiling loadable module kesher Linux - Software 3 04-10-2006 01:22 AM
Undefined reference to WxGtk libraries when compiling Xchm Darwish Linux - Software 0 09-03-2005 11:11 PM
undefined reference to `cfb_fillrect' and more when compiling kernel KR-data Linux - Software 0 09-03-2005 01:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration