Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 403
    • Issues 403
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #2148
Closed
Open
Created Dec 05, 2006 by Markus Weigel@mwgGuest

strange compile error when using modules instead of include files

Bugzilla Link 333
Created on Dec 05, 2006 15:13
Resolution FIXED
Resolved on Dec 07, 2006 11:04
Version svn
OS Linux
Architecture Other

Extended Description

I observed a strange compile error (actually a linker error) when separating 
some of my own sac functions (in this example: double2GrayLevels) from the file 
containing the main function. I created a new module (in the following examples 
"MyModule") in which I placed double2GrayLevels. When trying to "use" MyModule 
in the main file, I get several similar error messages of the form 
 
: In function `SACwf_String__tos__b_S': 
: undefined reference to `SACbtos' 
 
Using an include file instead of the module will cause these error messages to 
vanish, which seems rather strange to me. 
 
Additionally, when exchanging some statements in function main, the error will 
also vanish. I added some special comments on those lines in the source code. 
 
compiler flags: -O3 -nophm -E/opt/local/lib 
 
Files: MyModule.sac, MyModule_incl.sac, module_xmpl.sac 
 
 
------------------------------------------------------------------------ 
MyModule.sac: 
 
module MyModule; 
 
use Structures: all; 
 
/* export all; */ 
provide {double2GrayLevels}; 
 
 
/* Converts an array of double values to an array of 
 * graylevel colors ranging from 0 to 255 */ 
 
color[*] double2GrayLevels(double[*] image) { 
  /* determine minimum and maximum values */ 
  min = minval(image); 
  max = maxval(image); 
 
  /* normalize double values */ 
  image = (image - min)*(255.0/(max-min)); 
 
  /* convert image to array of color values */ 
 
  image_gray =  
    with { 
      ( . <= iv <= . ): newColor(genarray([3],toi(image[iv]))); 
      } : genarray(shape(image),black()); 
   
  return(image_gray); 
 
} 
 
 
/* Converts an array of doubles to an array of 
 * graylevels unsing a Hounsfield window. Values below  
 * winMin will be set to zero, values above winMax will 
 * be set to 255. All intermediate values will be scaled 
 * between 0 and 255. */ 
 
color[*] double2GrayLevels(double[*] image, double winMin, double winMax) { 
 
  /* Scale double values */ 
  image = (image - winMin)*(255.0/(winMax-winMin)); 
 
  /* convert image to array of color values */ 
  image_gray =  
    with { 
      ( . <= iv <= . ) { color = toi(image[iv]); 
			 if (color < 0) color=0;  
			 if (color > 255) color=255; 
      }: newColor(genarray([3],color)); 
    }: genarray(shape(image),black()); 
 
  return(image_gray); 
 
} 
 
 
------------------------------------------------------------------------ 
MyModule_incl.sac: 
 
/*module MyModule; 
 
use Structures: all;*/ 
 
/* export all; */ 
/*provide {double2GrayLevels}; */ 
 
 
/* Converts an array of double values to an array of 
 * graylevel colors ranging from 0 to 255 */ 
 
color[*] double2GrayLevels(double[*] image) { 
  /* determine minimum and maximum values */ 
  min = minval(image); 
  max = maxval(image); 
 
  /* normalize double values */ 
  image = (image - min)*(255.0/(max-min)); 
 
  /* convert image to array of color values */ 
 
  image_gray =  
    with { 
      ( . <= iv <= . ): newColor(genarray([3],toi(image[iv]))); 
      } : genarray(shape(image),black()); 
   
  return(image_gray); 
 
} 
 
 
/* Converts an array of doubles to an array of 
 * graylevels unsing a Hounsfield window. Values below  
 * winMin will be set to zero, values above winMax will 
 * be set to 255. All intermediate values will be scaled 
 * between 0 and 255. */ 
 
color[*] double2GrayLevels(double[*] image, double winMin, double winMax) { 
 
  /* Scale double values */ 
  image = (image - winMin)*(255.0/(winMax-winMin)); 
 
  /* convert image to array of color values */ 
  image_gray =  
    with { 
      ( . <= iv <= . ) { color = toi(image[iv]); 
			 if (color < 0) color=0;  
			 if (color > 255) color=255; 
      }: newColor(genarray([3],color)); 
    }: genarray(shape(image),black()); 
 
  return(image_gray); 
 
} 
 
------------------------------------------------------------------------ 
module_xmpl.sac: 
 
use StdIO: all; 
import Array: all; 
import Structures: all; 
use SDLdisplay: all; 
 
 
/* compile error arises if we use the module MyModule. If we use 
 * the include file instead, the error vanishes */ 
 
use MyModule: all; 
/* #include "MyModule_incl.sac" */ 
 
double[*] foo(int[.] shp) { 
  return(genarray(shp,0d)); 
} 
 
void foo2(color[*] arr) { 
  /* do not do anything interesting */ 
  a = 1; 
} 
 
int main() { 
  shp = [64,64]; 
   
  /* open file */ 
  errcode, fd = binfopen("/any/file/you/like", 
			 O_RDONLY()); 
 
  /* read 2D image as an array of doubles */ 
  image_2D = binfReadDoubleArray(fd,shape(shp)[[0]],shp); 
 
  /* uncomment one of the following lines and 
   * the compiler error will vanish */ 
 
/*   image_2D = foo(shp); */ 
/*   image_2D = genarray(shp,1d); */ 
 
  /* initialize display */ 
  disp = initDisplay(take([2],shp)); 
 
  gl = double2GrayLevels(image_2D); 
   
  /* unsing foo2 here instead of drawArray will cause the 
   * compile error to vanish */ 
 
/*   foo2(gl); */ 
  drawArray(disp,gl); 
 
  destroyDisplay(disp); 
 
  return(0); 
}
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking