Results 1 to 7 of 7

Thread: multiple definitions not found

  1. #1
    Join Date
    Jan 2010
    Beans
    108
    Distro
    Ubuntu 10.04 Lucid Lynx

    multiple definitions not found

    I have a piece of c code which has been driving me up the wall.
    It basically does string-matching.
    And to store the results I made a small struct arraylist.

    If I include arraylist.h, I get "undefined reference" errors
    when including arraylist.c I get "multiple definition" errors.

    Somehow I can't manage this.

    Thanks in advance,
    Jake
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2007
    Location
    Christchurch, New Zealand
    Beans
    1,328
    Distro
    Ubuntu

    Re: multiple definitions not found

    Ok I made it compile for you. revised archive attached...

    It compiles as follows: g++ *.cpp *.c
    then run as ./a.out

    I'm not quite sure what was going wrong for you, but it is best to only have declarations in header files and that means any file that you specify with #include even if it doesn't have .h suffix.

    So I put declarations for the functions you call from main into your arraylist.h header file and then included that in all the c and cpp files. I removed their inclusion from main.cpp and now they can all be compiled independently... and that was about all that was needed
    Attached Files Attached Files
    Last edited by worksofcraft; October 11th, 2010 at 07:46 AM.

  3. #3
    Join Date
    Jan 2010
    Beans
    108
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: multiple definitions not found

    I'm afraid that when I apply your strategy to all files (because I didn't include file_util.c for instance), it again fails to compile.

    I made an additional header for file_util.c and for boyer_moore_horspool.c

    Am I making the same mistake again?
    Attached Files Attached Files

  4. #4
    Join Date
    Sep 2007
    Location
    Christchurch, New Zealand
    Beans
    1,328
    Distro
    Ubuntu

    Re: multiple definitions not found

    Quote Originally Posted by JakeFrederix View Post
    I'm afraid that when I apply your strategy to all files (because I didn't include file_util.c for instance), it again fails to compile.

    I made an additional header for file_util.c and for boyer_moore_horspool.c

    Am I making the same mistake again?
    Well no... see it works just fine on my computer here:
    Code:
    $>ls
    a.out	     boyer_moore_horspool.c  file_util.h
    arraylist.c  boyer_moore_horspool.h  main.cpp
    arraylist.h  file_util.c	     Makefile
    $>g++ *.cpp *.c
    $>./a.out
    NAME
    	search1
    
    SYNOPSIS
    	./search1 <patroonbestand> <tekstbestand> ... <tekstbestand>
    
    DESCRIPTION
    	Doorzoekt een reeks tekstbestanden naar een patroon met behulp van het Boyer-Moore-Horspool algoritme.
    
    $>
    Mind you... IDK what is supposed to do though

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: multiple definitions not found

    If you are developing in C, then stick to it. There's no need to mix in C++. Your main.cpp should be renamed main.c, and the cstdlib should be renamed to stdlib.h; also the using namespace directive should be removed.

    Other than those issues, the following two warnings popped up when I compiled the app:
    Code:
    gcc -Wall -pedantic -std=c99 *.c
    arraylist.c: In function ‘list* arraylist_create()’:
    arraylist.c:9: warning: no return statement in function returning non-void
    main.c: In function ‘int main(int, char**)’:
    main.c:33: warning: unused variable ‘j’

  6. #6
    Join Date
    Jul 2008
    Beans
    1,491

    Re: multiple definitions not found

    Mind you... IDK what is supposed to do though
    It's a text search algorithm. You feed it a pattern in a file (first argument) then any number of text files to search through for that pattern.

    See also: http://en.wikipedia.org/wiki/Boyer–M...pool_algorithm

  7. #7
    Join Date
    Jan 2010
    Beans
    108
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: multiple definitions not found

    Thanks everyone!
    Works like a charm now.

    Jake

Tags for this Thread

Bookmarks

Posting Permissions

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