how to compile

Q

QQ

sorry it might not belong to this board, but I don't know where else to
post

I have a c source file and a library, how should I compile under linux?
I have using the command like


gcc -o test -l lib.a main.c

but it fails, displays like
undefined reference to `ing'
collect2: ld returned 1 exit status

Thanks
 
R

Richard Heathfield

QQ said:
sorry it might not belong to this board, but I don't know where else to
post

I have a c source file and a library, how should I compile under linux?
I have using the command like


gcc -o test -l lib.a main.c

Firstly, don't use test as a program name. test has a special meaning in
Linux.

Secondly, library names are traditionally in the form libfoo.a and are
linked using -lfoo (dropping the lib and the .a because gcc just assumes
them anyway). Note the absence of a space between -l and the library name.

Thirdly, put the library information at the end of the line, not in the
middle - for a library called libfoo.a use:

gcc -o mylittleprogram main.c -lfoo
 
C

Christopher Benson-Manica

QQ said:
I have a c source file and a library, how should I compile under linux?
I have using the command like
gcc -o test -l lib.a main.c
but it fails, displays like
undefined reference to `ing'
collect2: ld returned 1 exit status

(Take it to comp.unix.programmer. Looks like you've got a linking
problem.)

Your post is off-topic for comp.lang.c. Please visit

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

for posting guidelines and frequently asked questions. Thank you.
 
C

Christopher Benson-Manica

QQ said:
Thank you very much!

It is proper Usenet etiquette to include the relevant portions of the text
you are replying to. To do this using Google groups, please follow the
instructions below, penned by Keith Thompson:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
G

g.kanaka.raju

QQ said:
sorry it might not belong to this board, but I don't know where else to
post

I have a c source file and a library, how should I compile under linux?
I have using the command like


gcc -o test -l lib.a main.c

but it fails, displays like
undefined reference to `ing'
collect2: ld returned 1 exit status

Thanks

Try it in the following way.
gcc -o test main.c lib.a

If you still get liking error, then we need to see what symbol is
causing the error.

Regards,
Raju
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top