Find the answer to your Linux question:
Results 1 to 4 of 4
Its been a while since ive coded in C so just might be forgetting something. here is the error Code: gcc -c main.c main.c: In function `binary_search_tree_test': main.c:129: error: `BSTree' ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314

    error in c and i dont know why


    Its been a while since ive coded in C so just might be forgetting something.

    here is the error
    Code:
    gcc -c main.c
    main.c: In function `binary_search_tree_test':
    main.c:129: error: `BSTree' undeclared (first use in this function)
    main.c:129: error: (Each undeclared identifier is reported only once
    main.c:129: error: for each function it appears in.)
    main.c:129: error: `tree' undeclared (first use in this function)
    main.c:131: error: `BSTNode' undeclared (first use in this function)
    main.c:131: error: `temp' undeclared (first use in this function)
    main.c:136: error: parse error before ')' token
    make: *** [main.o] Error 1
    this is when i havent included the file here is the error when the file is included

    Code:
    gcc -c main.c
    gcc BSTree.o hash.o help_funcs.o main.o search.o -o proj2
    ld: fatal: symbol `BSTinsert' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `printBST' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `BSTHeight' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `BSTcreateNode' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `printHeight' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `BSTsearch' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `max' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: symbol `BSTinitialize' is multiply-defined:
            (file BSTree.o and file main.o);
    ld: fatal: File processing errors. No output written to proj2
    collect2: ld returned 1 exit status
    make: *** [proj2] Error 1
    im using gcc as the compiler. im using a standard makefile. usually with a make file i dont have to include the files in the project at the top of the program. does anybody know why this is happening.
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, it is a little hard to tell without the actual source code.

  3. #3
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Dolda,

    Are you back for good?
    The best things in life are free.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2003
    Posts
    7

    Re: error in c and i dont know why

    Declare your functions static whenever you want to include their definitions into .h file.

    Actually, you define the same global symbol into each translation unit, that causes linker to confuse of which global symbol definition to put into the resulting file.

    If you're defining a variable shared between translation units, declare it "extern" in header file and put the actual declaration into any translation unit, like:

    my.h
    extern int myvar;

    my1.c
    #include "my.h"
    int myvar; // The actual declaration

    my2.c
    #include "my.h"
    void func_that_uses_myvar () {
    myvar = 1;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •