ld usage

V

vichy.kuo

Dear all:
I try to write a simple program and use ld to link it as static.
But I get some link error as I attached at the end of my mail.
In the beginning, I thought maybe there is some libs I need to
include.
But the message says there is multiple definitions?
If I drop '-lc' or '-lpthread', ld will say it need any one of them.
Did I miss some options passing to ld?
Sincerely Yours,
vichy


#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
void *pmtthread_func(void* arg) {
printf("enter pthread\n");
}

int main(void)
{
unsigned char* ptmp;
pthread_t pmtthread;
pthread_create(&pmtthread, NULL, pmtthread_func, NULL);

getchar();
ptmp = malloc(sizeof(unsigned char)*128);
ptmp[0]=100;
ptmp[1]=1;

printf("ptmp[0] = %d\n",ptmp[0]);
pthread_join(pmtthread, NULL);

return 0;
}
# gcc -c test.c
# ls
a.out mips test.c test_mips test.o
# ld -static -o test test.o -lc -lpthread
/usr/lib/libpthread.a(lowlevellock.o): In function
`__lll_lock_wait_private':
(.text+0x0): multiple definition of `__lll_lock_wait_private'
/usr/lib/libc.a(libc-lowlevellock.o):(.text+0x0): first defined here
/usr/lib/libpthread.a(lowlevellock.o): In function
`__lll_unlock_wake_private':
(.text+0x100): multiple definition of `__lll_unlock_wake_private'
/usr/lib/libc.a(libc-lowlevellock.o):(.text+0x30): first defined here
ld: warning: cannot find entry symbol _start; defaulting to
00000000080480c0
/usr/lib/libc.a(ioputs.o): In function `puts':
(.text+0x16d): undefined reference to `_Unwind_Resume'
........
 
S

Seebs

If I drop '-lc' or '-lpthread', ld will say it need any one of them.
Did I miss some options passing to ld?

1. Basically, this is the wrong group. Your question has to do with your
particular host system, not to do with the C language.
2. There is almost never a reason to invoke ld. Use gcc to link things.
(That may or may not solve your problem, but I've found a lot of people
who have weird problems invoking ld directly don't when they use gcc.)

-s
 
N

Noob

vichy said:
I try to write a simple program and use ld to link it as static.

gcc -v -static -pthread -Wall -Wextra test.c -o foo
(Don't call your executable "test".)

These questions are better answered in comp.unix.programmer
 

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,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top