Menu

#4 Undefined Reference

open
nobody
None
9
2012-10-25
2006-05-28
Phuc H. Dao
No

I installed the CUnit 2.1-0. I ran the example from
the CUnit example page that test the fprintf and fread.
When I compile it using the following Makefile, I get
many errors. Please take a look below and let me know
what am missing. The online example is also attach to
this post.

Makefile:

rule = -pedantic -Wall -ansi -O2

OnlineExample: clean OnlineExample.o
gcc $(rule) -o OE OnlineExample.o

OnlineExample.o: OnlineExample.c
gcc -c OnlineExample.c

clean:
rm -f core. .o

I get these errors when I compile:

[phuchdao@HoangHao LATA]$ make OnlineExample
rm -f core. .o
gcc -c OnlineExample.c
gcc -pedantic -Wall -ansi -O2 -o OE OnlineExample.o
OnlineExample.o(.text+0xca): In function testFPRINTF': : undefined reference toCU_assertImplementation'
OnlineExample.o(.text+0x10a): In function testFPRINTF': : undefined reference toCU_assertImplementation'
OnlineExample.o(.text+0x14d): In function testFPRINTF': : undefined reference toCU_assertImplementation'
OnlineExample.o(.text+0x1b6): In function testFREAD': : undefined reference toCU_assertImplementation'
OnlineExample.o(.text+0x1f5): In function testFREAD': : undefined reference toCU_assertImplementation'
OnlineExample.o(.text+0x222): In function main': : undefined reference toCU_initialize_registry'
OnlineExample.o(.text+0x22b): In function main': : undefined reference toCU_get_error'
OnlineExample.o(.text+0x24a): In function main': : undefined reference toCU_add_suite'
OnlineExample.o(.text+0x25b): In function main': : undefined reference toCU_cleanup_registry'
OnlineExample.o(.text+0x260): In function main': : undefined reference toCU_get_error'
OnlineExample.o(.text+0x27a): In function main': : undefined reference toCU_add_test'
OnlineExample.o(.text+0x296): In function main': : undefined reference toCU_add_test'
OnlineExample.o(.text+0x2a2): In function main': : undefined reference toCU_cleanup_registry'
OnlineExample.o(.text+0x2a7): In function main': : undefined reference toCU_get_error'
OnlineExample.o(.text+0x2b6): In function main': : undefined reference toCU_basic_set_mode'
OnlineExample.o(.text+0x2be): In function main': : undefined reference toCU_basic_run_tests'
OnlineExample.o(.text+0x2c3): In function main': : undefined reference toCU_cleanup_registry'
OnlineExample.o(.text+0x2c8): In function main': : undefined reference toCU_get_error'
collect2: ld returned 1 exit status
make: *** [OnlineExample] Error 1

Please let me know what is going on.

Discussion

  • Phuc H. Dao

    Phuc H. Dao - 2006-05-28

    Online Example

     
  • Nobody/Anonymous

    Logged In: NO

    -lcunit should be added.

     
  • Phuc H. Dao

    Phuc H. Dao - 2006-06-02

    Logged In: YES
    user_id=1530227

    Thank you nobody for helping with my problem. After
    spending time reading about the -L option in gcc, I
    managed to get the library CUnit to link to the program.
    I'm not sure if there's a reply button on this page or
    not, but I haven't see one. That's why I'm replying you
    through this comment box.

     
  • Nobody/Anonymous

    Logged In: NO

    You are not linking against the library. you have to have a library named libcunit.lib
    and include it during linking.

     

Anonymous
Anonymous

Add attachments
Cancel