Error need help


 
Thread Tools Search this Thread
Top Forums Programming Error need help
# 8  
Old 07-05-2006
Comment out this line:
Code:
extern char *strerror(int errno);

strerror is defined in string.h so your declaration is redundant. I'm guessing it must have been needed on some other system that didn't declare it in string.h, so if you want to be really thorough, you could do something like:

Code:
// Near top util.h
#include <string.h>

// Lower down
#ifndef strerror
extern char *strerror(int errno);
#endif/*strerror*/

Including string.h more than once shouldn't hurt because it has start and end code like this:

Code:
// Start of file
#ifndef __STRING_H__
#define __STRING_H__

// file contents
...

#endif/*__STRING_H__*/

I add these to all my .h files just to be safe.
# 9  
Old 07-05-2006
strerror() is declared in string.h according to ISO
It's strange that this code worked earlier
# 10  
Old 07-06-2006
Dear Corona

If I comment out this what I will get in error

couliba@linux:~/bin/GaSource> make find_rules
cc find_rules.c -o find_rules
/tmp/ccsfOXjS.o(.text+0x72): In function `main':
find_rules.c: undefined reference to `seed'
/tmp/ccsfOXjS.o(.text+0x18e):find_rules.c: undefined reference to `print_help_message'
/tmp/ccsfOXjS.o(.text+0x23d):find_rules.c: undefined reference to `read_cline'
/tmp/ccsfOXjS.o(.text+0x679):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x68c):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x69f):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x6e5):find_rules.c: undefined reference to `define_function'
/tmp/ccsfOXjS.o(.text+0x702):find_rules.c: undefined reference to `define_tree'
/tmp/ccsfOXjS.o(.text+0x789):find_rules.c: undefined reference to `init_data'
/tmp/ccsfOXjS.o(.text+0x821):find_rules.c: undefined reference to `read_data'
/tmp/ccsfOXjS.o(.text+0x850):find_rules.c: undefined reference to `normalize_price'
/tmp/ccsfOXjS.o(.text+0xe30):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0xe61):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0xf30):find_rules.c: undefined reference to `new_tree'
/tmp/ccsfOXjS.o(.text+0x10fa):find_rules.c: undefined reference to `create_population'
/tmp/ccsfOXjS.o(.text+0x1151):find_rules.c: undefined reference to `create_offspring'
/tmp/ccsfOXjS.o(.text+0x11da):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1210):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x123f):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x12a1):find_rules.c: undefined reference to `compute_statistics'
/tmp/ccsfOXjS.o(.text+0x12b8):find_rules.c: undefined reference to `cluster_population'
/tmp/ccsfOXjS.o(.text+0x14cf):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1505):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x1534):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x17ce):find_rules.c: undefined reference to `copy_genome'
/tmp/ccsfOXjS.o(.text+0x1b79):find_rules.c: undefined reference to `save_genome'
/tmp/ccsfOXjS.o(.text+0x1c24):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1c5e):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x1c91):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x1d9f):find_rules.c: undefined reference to `dispose_population'
/tmp/ccsfOXjS.o(.text+0x1de3):find_rules.c: undefined reference to `descending_order'
/tmp/ccsfOXjS.o(.text+0x1dfc):find_rules.c: undefined reference to `order_by_key'
/tmp/ccsfOXjS.o(.data+0x50): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x54): undefined reference to `eval_if_then'
/tmp/ccsfOXjS.o(.data+0xa0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0xa4): undefined reference to `eval_if_then_else'
/tmp/ccsfOXjS.o(.data+0xf0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0xf4): undefined reference to `eval_and'
/tmp/ccsfOXjS.o(.data+0x140): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x144): undefined reference to `eval_or'
/tmp/ccsfOXjS.o(.data+0x190): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x194): undefined reference to `eval_not'
/tmp/ccsfOXjS.o(.data+0x1e0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x1e4): undefined reference to `eval_greater'
/tmp/ccsfOXjS.o(.data+0x230): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x234): undefined reference to `eval_less'
/tmp/ccsfOXjS.o(.data+0x278): undefined reference to `init_boolean'
/tmp/ccsfOXjS.o(.data+0x27c): undefined reference to `read_boolean'
/tmp/ccsfOXjS.o(.data+0x280): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x2d4): undefined reference to `eval_flip'
/tmp/ccsfOXjS.o(.data+0x320): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x324): undefined reference to `eval_plus'
/tmp/ccsfOXjS.o(.data+0x370): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x374): undefined reference to `eval_minus'
/tmp/ccsfOXjS.o(.data+0x3c0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x3c4): undefined reference to `eval_multiply'
/tmp/ccsfOXjS.o(.data+0x410): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x414): undefined reference to `eval_divide'
/tmp/ccsfOXjS.o(.data+0x460): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x464): undefined reference to `eval_negation'
/tmp/ccsfOXjS.o(.data+0x4b0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x4b4): undefined reference to `eval_norm'
/tmp/ccsfOXjS.o(.data+0x500): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x504): undefined reference to `eval_average'
/tmp/ccsfOXjS.o(.data+0x550): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x554): undefined reference to `eval_maximum'
/tmp/ccsfOXjS.o(.data+0x5a0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x5a4): undefined reference to `eval_minimum'
/tmp/ccsfOXjS.o(.data+0x5f0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x5f4): undefined reference to `eval_slope'
/tmp/ccsfOXjS.o(.data+0x640): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x644): undefined reference to `eval_volatility'
/tmp/ccsfOXjS.o(.data+0x690): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x694): undefined reference to `eval_lag'
/tmp/ccsfOXjS.o(.data+0x6e0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x6e4): undefined reference to `eval_data'
/tmp/ccsfOXjS.o(.data+0x728): undefined reference to `init_real'
/tmp/ccsfOXjS.o(.data+0x72c): undefined reference to `read_real'
/tmp/ccsfOXjS.o(.data+0x730): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x784): undefined reference to `eval_price'
/tmp/ccsfOXjS.o(.data+0x7d4): undefined reference to `eval_compounded'
collect2: ld returned 1 exit status
make: *** [find_rules] Error 1


and If add the code as the below

/*------------------------------------------------------------------------------

File: util.h
Date: January 26, 1992

Copyright (c) Risto Karjalainen. All rights reserved.

Utility functions of general use.

------------------------------------------------------------------------------*/
#inlcude <string.h>

#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#ifndef strerror
extern char *strerror(int errno);
#endif

/*------------------------------------------------------------------------------
'get_boolean' prints '*prompt' and reads a character from stdin. 'answers'
contains the valid character set. If the entered character equals 'affirm',
'def' is returned.
------------------------------------------------------------------------------*/

extern int get_boolean(char *prompt, char *answers, int def, char affirm);

/*------------------------------------------------------------------------------
'get_int' prints '*prompt' and reads an integer from stdin. The entered
integer must be in the range 'min' .. 'max'. If none is entered, 'def'
is returned, instead.
*/

I will receive this error

ouliba@linux:~/bin/GaSource> make find_rules
cc find_rules.c -o find_rules
In file included from find_rules.c:19:
util.h:17: error: conflicting types for `strerror'
/usr/include/string.h:256: error: previous declaration of `strerror'
find_rules.c: In function `main':
find_rules.c:203: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:248: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:315: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
make: *** [find_rules] Error 1
couliba@linux:~/bin/GaSource>


Any more advise, I appreciate so much



Quote:
Originally Posted by Corona688
Comment out this line:
Code:
extern char *strerror(int errno);

strerror is defined in string.h so your declaration is redundant. I'm guessing it must have been needed on some other system that didn't declare it in string.h, so if you want to be really thorough, you could do something like:

Code:
// Near top util.h
#include <string.h>

// Lower down
#ifndef strerror
extern char *strerror(int errno);
#endif/*strerror*/

Including string.h more than once shouldn't hurt because it has start and end code like this:

Code:
// Start of file
#ifndef __STRING_H__
#define __STRING_H__

// file contents
...

#endif/*__STRING_H__*/

I add these to all my .h files just to be safe.
# 11  
Old 07-07-2006
That error is what Corona is trying to help you with - you have strerror declared in util.h. Put the #ifndef and #define statement he gave you around the place where you encounter the error in util.h.

To find where strerror is doubly defined try this:
Code:
gcc -E find_rules.c | grep 'strerror'

You will see something like "extern char *strerror" appearing twice. It should show up only once.
# 12  
Old 07-07-2006
Those errors are exactly what it says they are. It cannot find those functions. You probably need to compile another file to get them. Not all C files are standalone. The general sequence is:

Code:
cc -c file1.c -o file1.o
cc -c file2.c -o file2.o
...
cc -c file5.c -o file5.o
cc file1.o file2.o file3.o file4.o file5.o -o program

In a makefile you might have something like:
Code:
OBJS=file1.o file2.o file3.o file4.o file5.o

program:$(OBJS)
        $(CC) $(OBJS) $(LDFLAGS) -o $@

It should already understand how to convert .c to .o, so you just tell it how to convert those .o's to one executable. LDFLAGS is an optional variable that might comtain library flags.

And please, for the love of yog, put your code in code-tags!!

Last edited by Corona688; 07-07-2006 at 11:26 AM..
# 13  
Old 07-08-2006
Quote:
Originally Posted by Corona688
Those errors are exactly what it says they are. It cannot find those functions. You probably need to compile another file to get them. Not all C files are standalone. The general sequence is:

Code:
cc -c file1.c -o file1.o
cc -c file2.c -o file2.o
...
cc -c file5.c -o file5.o
cc file1.o file2.o file3.o file4.o file5.o -o program

In a makefile you might have something like:
Code:
OBJS=file1.o file2.o file3.o file4.o file5.o

program:$(OBJS)
        $(CC) $(OBJS) $(LDFLAGS) -o $@

It should already understand how to convert .c to .o, so you just tell it how to convert those .o's to one executable. LDFLAGS is an optional variable that might comtain library flags.

And please, for the love of yog, put your code in code-tags!!
Your advice may be a solution to my problem, but I am not sure if I understand what you want me to do. Can you please put in away I can understand.

As you said. it can not find those function. that is right but how do I make it to find those function.

Thank you very much
# 14  
Old 07-10-2006
This might best be shown by example.

In a directory by itself, create this file:
Code:
// main.c
#include <stdio.h>

int main(int argc, char *argv[])
{
  int n;
  fprintf(stderr,"main(%d,[",argc);
  for(n=0; n<argc; n++)
    fprintf(stderr," '%s'",argv[n]);
  fprintf(stderr," ]);\n");
  return(0);
}

Then compile and run it like this:
Code:
# gcc main.c -o main
# ./main
main(1,[ './main' ]);
#

That works, but what you might not realize is that gcc is actually doing two steps, not one -- compilation, then linking. The compilation stage converts C code into assembly language, the linking stage ties everything together into an executable. Let's break it into two steps:
Code:
# gcc -c main.c -o main.o
# gcc main.o -o main
# ./main
main(1,[ './main' ]);
#

That's what gcc is ACTUALLY doing... converts the C file into an object file(.o), then links the object file into an executable.

Now let's try and use a function from another .c file. First, create this file:
Code:
// library.c
#include <stdio.h>

int library_function(int c)
{
  fprintf(stderr,"library_function(%d)\n",c);
  return(c-3);
}

Then, modify main.c to use it like this:
Code:
#include <stdio.h>

extern int library_function(int c);

int main(int argc, char *argv[])
{
  int n;
  fprintf(stderr,"main(%d,[",argc);
  for(n=0; n<argc; n++)
    fprintf(stderr," '%s'",argv[n]);
  fprintf(stderr," ]);\n");

  printf("library_function(%d) returns %d\n",32,library_function(32));

  return(0);
}

Finally, let's see what happens when we try and compile it, then link it:
Code:
# gcc -c main.c -o main.o
# gcc main.o -o main
main.o: In function `main':
main.c:(.text+0x86): undefined reference to `library_function'
collect2: ld returned 1 exit status
#

It doesn't work. It compiles it fine since there's no syntax errors in the program, but the function it wants is not in main.o! To get that function, we'll need to give it library.o too.
Code:
# gcc -c main.c -o main.o
# gcc -c library.c -o library.o
# gcc main.o library.o -o main
# ./main
main(1,[ './main' ]);
library_function(32)
library_function(32) returns 29
#

It works!

Now, if you want your makefile to do that, you need to tell it that the output file needs main.o and library.o. Here's a simple makefile:
Code:
main:main.o library.o
        $(CC) main.o library.o $(LDFLAGS) -o $@
clean:
        rm -f main main.o library.o

With that makefile in the main directory, let's try it:
Code:
# make clean
rm -f main main.o library.o
# make main
cc    -c -o main.o main.c
cc    -c -o library.o library.c
cc main.o library.o  -o main
# ./main
main(1,[ './main' ]);
library_function(32)
library_function(32) returns 29
#

It works!

So there you go. You'll need to find the .c file that these missing functions reside in, convert it to an object, then link it into your executable.

Last edited by Corona688; 07-11-2006 at 11:25 AM.. Reason: mistake in examples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

2. Solaris

Rpcinfo: can't contact portmapper: RPC: Authentication error; why = Failed (unspecified error)

I have two servers with a fresh install of Solaris 11, and having problems when doing rpcinfo between them. There is no firewall involved, so everything should theoretically be getting through. Does anyone have any ideas? I did a lot of Google searches, and haven't found a working solution yet. ... (2 Replies)
Discussion started by: christr
2 Replies

3. Shell Programming and Scripting

What is this error log = hda: irq timeout: error=0x00 and how to solve?

what is this error log = hda: irq timeout: error=0x00 and how to solve? every day upon checking the logs i see this error. hda: irq timeout: error=0x00 hda: irq timeout: error=0x00 hda: irq timeout: error=0x00 hda: irq timeout: error=0x00 hw_client: segfault at 0000000000000046 rip... (3 Replies)
Discussion started by: avtalan
3 Replies

4. UNIX for Dummies Questions & Answers

> 5 ")syntax error: operand expected (error token is " error

im kinda new to shell scripting so i need some help i try to run this script and get the error code > 5 ")syntax error: operand expected (error token is " the code for the script is #!/bin/sh # # script to see if the given value is correct # # Define errors ER_AF=86 # Var is... (4 Replies)
Discussion started by: metal005
4 Replies

5. UNIX for Advanced & Expert Users

ssh error: Error reading response length from authentication socket

Hi - I am getting the error `Error reading response length from authentication socket' when I ssh from my cluster to another cluster, and then back to my cluster. It doesn't seem to affect anything, but it's just annoying that it always pops up and tends to confuse new users of the cluster. I... (1 Reply)
Discussion started by: cpp6f
1 Replies

6. Solaris

fssnap error :snapshot error: File system could not be write locked

Hi Guys. This is part of my filesystem structure : Filesystem size used avail capacity Mounted on /dev/md/dsk/d0 47G 5.2G 42G 12% / /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% ... (2 Replies)
Discussion started by: aggadtech08
2 Replies

7. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

8. UNIX for Advanced & Expert Users

VSI-FAX error - Cannot login to server and Connecto error to host

I encounters a VSIFAX related error: vfxstat: Cannot login to server on rsac3: Connect error to host 172.16.1.45: Invalid argument It started happening last night with a core dump. Then we can't start VSIFAX again. I am runing VSI-FAX 4.2 on AIX box (0 Replies)
Discussion started by: b_jin
0 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. UNIX for Dummies Questions & Answers

Error: Internal system error: Unable to initialize standard output file

Hey guys, need some help. Running AIX Version 5.2 and one of our cron jobs is writing errors to a log file. Any ideas on the following error message. Error: Internal system error: Unable to initialize standard output file I'm guessing more info might be needed, so let me know. Thanks (2 Replies)
Discussion started by: firkus
2 Replies
Login or Register to Ask a Question