Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The error:

farah@farah-VirtualBox:~$ gcc libmy_string.a
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

and the code for the library is as follows:

library : my_string.o<br>
    ar rcs libmy_string.a my_string.o<br>
run: string_compare.c<br>
    gcc -o run string_compare.o -L. -lmy_string<br>
string_compare.o: string_compare.c my_string.h<br>
            gcc -c string_compare.c<br>
my_string.o: my_string.c my_string.h<br>
            gcc -c my_string.c<br>

library : my_string.o<br>
    ar rcs libmy_string.a my_string.o<br>
.PHONY: clean<br>
clean:<br>
    rm -rf *.o run<br>

Additional information: My main method is in string_compare.c and method and header are my_string.c and my_string.h respectively.

share|improve this question
Please try asking at Unix & Linux or StackOverflow.com – ObsessiveSSOℲ Oct 8 '12 at 12:15

closed as off topic by Lekensteyn, ObsessiveSSOℲ, devav2, fossfreedom Oct 8 '12 at 14:16

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Programming questions are offtopic here afaik. But I suggest you to have a look at this question.

You have to specify a main function or tell the linker which function it should use instead.

Assuming your entry point should be string_compare() you have to add -Wl,-estring_compare as options to your gcc call.

share|improve this answer