Discuss Problems with compiling in the C Programming forum on Dev Shed. Problems with compiling C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 34 m 4 sec
Reputation Power: 0
Problems with compiling
I am trying to compile this but I get:
gcc -Wall -O4 -funroll-all-loops -fschedule-insns -malign-double -c shotrec2tt.c -o shotrec2tt.o
shotrec2tt.c: In function ‘main’:
shotrec2tt.c:39: warning: ‘rfname’ may be used uninitialized in this function
shotrec2tt.c:39: warning: ‘sfname’ may be used uninitialized in this function
shotrec2tt.c:43: warning: ‘mag_l’ may be used uninitialized in this function
shotrec2tt.c:43: warning: ‘mag_md’ may be used uninitialized in this function
gcc -Wall -O4 -funroll-all-loops -fschedule-insns -malign-double -o shotrec2tt shotrec2tt.o gi_line.o -lm
shotrec2tt.o: In function `main':
shotrec2tt.c.text+0xb33): undefined reference to `distaz'
collect2: ld returned 1 exit status
make: *** [shotrec2tt] Error 1
this is the code:
char *rfname, *sfname, string[MAXL];
int i, j, k, nr, ns, n_ml, verbose, sflg, lflg;
float *mag_l, *mag_md;
float vel, s_vel, dist, az, baz, xdeg;
Time spent in forums: 2 Months 4 Weeks 1 Day 17 h 18 m 9 sec
Reputation Power: 1827
Mmm, is this code you "found" somewhere?
Because this style of function definition has been obsolete for over 20 years.
> int get_line(), distaz();
> gcc -Wall -O4 -funroll-all-loops -fschedule-insns -malign-double -o shotrec2tt shotrec2tt.o gi_line.o -lm
Since get_line() isn't defined in this source code, I guess it is in gi_line.c
Is there by any chance any other .c file lying around in the directory?
Does it by any chance have the definition for distaz() ?
* Creates a travel time file based on a shot and receiver file
* in xy.....
* ari 05-02
* V 1.1
* Now also includes S-wave travel times.
* ari Oct 2009
* V 2.0
* Allows selection on magnitude distance.
* ari Mar 2010
#define VER 2.0
#define FIX 0
#define AUTHOR "Ari Tryggvason"
#define DATE "100323"
#define MAXL 256
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP: Please don't be a help vampire!
Time spent in forums: 1 Month 4 Days 5 h 13 m 15 sec
Reputation Power: 1801
All the "uninitialised" warnings mean what they say - when optimisation is used the compiler can perform a level of abstract execution analysis to prove potential execution paths that result in use of an initialised value. These paths are theoretical and may not actually occur in real execution due to the nature of the input data and semantic mutual exclusivity of apparently independent conditions which is runtime information the compiler does not have.
Either way initialising the data is the simple solution, if only to suppress the warning, however you should manually analyse the code to determine whether the error path is valid and can occur, and if so whether the default initialisation is adequate.
With respect to the undefined symbol "distaz", here you have an unusual and frankly lazy function declaration:
int get_line(), distaz();
but there is no definition of distaz() and where it is called, it takes a number of arguments, that are not explicitly declared.
Ultimately your attempt to perform such extreme optimisation on this code is probably pointless and ill-advised. The code execution performance will be entirely constrained by the file I/O performance, and no amount of compiler optimisation is likely to make a significant difference. If you were to profile this code you would probably observe that it spends most of its time in library code (particularly the I/O functions) over which you have little control.
Moreover since you have obviously never had this code compile since it is incomplete, you should not start with optimisation on since that precludes useful and intelligible use of a debugger.
You'd be better off "modernising" this code, and concentrating on getting it to compile (for which you'll need the missing function definition). I strongly suggest that you switch off the optimisation options and switch on the extended warning levels - I'd recommend -Wall -Werror -Wformat. The code would benefit from fixing any warnings generated.