gcc컴파일 하는데 이상하네여.
글쓴이: 익명 사용자 / 작성시간: 월, 2002/05/27 - 12:16오후
gcc 컴파일을 하는데 컴파일이 안되고 이런 결과가 나오는군요...
$gcc -lpthread -o tpool tpool.c
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.oIn
function '_start' /usr/lib/gcc-lib/i386-redhat-
linux/2.96/../../../crt1.o<.text+0x18>undefined reference to 'main'
collect2 ld returned 1 exit status
이렇게 말이죠
이게 무슨 소린지.... 아예 이해가 안가네요.
컴파일 해도 실행파일도 안나오네요.
그리고 다른 파일을 컴파일 하는 경우엔 또 이렇게 뜹니다
$gcc -lpthread -o tpooltest tpooltest.c
/tmp/ccj4vhpp.o In function 'main'
/tmp/ccj4vhpp.o<.text+0x65> undefined reference to 'tpool_init'
이것도 이해가 안가는건 마찬가지 인데 /tmp/ccj4vhpp.o 여기에 함수에
서 <.text+0x65>여기 텍스트 를 얘기하는것 같은데...
이게 무슨 말이고 왜 이런 메시지가 뜨는건지 궁금합니다.
고수님들께 많은 부탁 드립니다.
그럼........
Forums:
Re: gcc컴파일 하눈데 이상하네여.
tpool.c 에 main() 이 있나요?
Re^3: gcc컴파일 하눈데 이상하네여.윗말의 보정
gcc -o tpool tpooltest.c tpool.c -lpthread
한국축구 장하다~~
Re^4: 라이브러리 만들어도 되죠
아래와 같이 메이크 파일을 만들어서
라이브러리 만들고,,
# Makefile
LD_HOME = $(HOME)
AR = ar
SYSTEM_INCL =
COMMON_INCL = -I$(LD_HOME)/include
LOCAL_INCL =
INCLUDE = $(LOCAL_INCL) $(COMMON_INCL) $(SYSTEM_INCL)
LIBNAME =$(LD_HOME)/lib/libtpool.a
CFLAGS = -g -c -D_$(HWPLATFORM)_ $(INCLUDE)
ARFLAGS = -ruv
.SUFFIXES .c .o .cp
.c.o
$(CC) $(CFLAGS) $*.c
# OBJS list
OBJS = tpool.o
alllib
lib $(OBJS)
$(AR) $(ARFLAGS) $(LIBNAME) $(OBJS)
clean
rm -f *.o core
------------------------------------------------
gcc -o tpool tpooltest.c -ltpool -lpthread
이런식으로 사용하셔도 됩니다.
http//kldp.org/HOWTO/html/Program-Library-HOWTO/
Re: 한글 좀 잘 쓰시길 바랍니다.
정확한 맞춤법을 사용하시길 바랍니다.
"하눈데", "구럼" 이런 표현을 사용하시는데 초등학교는 다니셨습니까 ?
프로그램을 하실 정도면 정규 교육을 받으셨을 것이고
그렇다면 사고 능력은 있다고 보여집니다.
다시 한번 부탁드립니다. 정확한 한글 표현 부탁드립니다.
수고하십시요.
Re: 짜증나는 친구네..
이 친구야.
한글이나 똑바로 써.
답해주는 사람이나 쯨쯨..
Re^2: gcc컴파일 하는데 이상하네요.윗말의 보정
아 main이 보니까 없네요.
그래서 그런 에러가 났나봅니다. 그럼 이 파일을 컴파일을 할 수 없는 건
가요?
제가 짠 파일이 아니라서 파일 보고 분석을 하려고 하는데...
그럼 파일 두개를 보여드릴께요
두 파일을 어떻게 컴파일해서 실행할수 있는지 가르쳐주시면 감사하겠습니
다.
tpool.c 파일
#include
#include
#include
#include
#include
#include
#include "tpool.h"
void *tpool_thread(void *);
void tpool_init(tpool_t *tpoolp,
int num_worker_threads,
int max_queue_size,
int do_not_block_when_full)
{
int i, rtn;
tpool_t tpool;
/* allocate a pool data structure */
if ((tpool = (tpool_t )malloc(sizeof(struct tpool))) == NULL)
perror("malloc"), exit(1);
/* initialize th fields */
tpool->num_threads = num_worker_threads;
tpool->max_queue_size = max_queue_size;
tpool->do_not_block_when_full = do_not_block_when_full;
if ((tpool->threads =
(pthread_t *)malloc(sizeof(pthread_t)*num_worker_threads))
== NULL)
perror("malloc"), exit(1);
tpool->cur_queue_size = 0;
tpool->queue_head = NULL;
tpool->queue_tail = NULL;
tpool->queue_closed = 0;
tpool->shutdown = 0;
if ((rtn = pthread_mutex_init(&(tpool->queue_lock), NULL)) != 0)
fprintf(stderr,"pthread_mutex_init %s",strerror(rtn)), exit(1);
if ((rtn = pthread_cond_init(&(tpool->queue_not_empty), NULL)) !=
0)
fprintf(stderr,"pthread_cond_init %s",strerror(rtn)), exit(1);
if ((rtn = pthread_cond_init(&(tpool->queue_not_full), NULL)) != 0)
fprintf(stderr,"pthread_cond_init %s",strerror(rtn)), exit(1);
if ((rtn = pthread_cond_init(&(tpool->queue_empty), NULL)) != 0)
fprintf(stderr,"pthread_cond_init %s",strerror(rtn)), exit(1);
/* create threads */
for (i = 0; i != num_worker_threads; i++) {
if ((rtn = pthread_create( &(tpool->threads[i]),
NULL,
tpool_thread,
(void *)tpool)) != 0)
fprintf(stderr,"pthread_create %d",rtn), exit(1);
}
*tpoolp = tpool;
}
int tpool_add_work(
tpool_t tpool,
void (*routine)(),
void *arg)
{
int rtn;
tpool_work_t *workp;
if ((rtn = pthread_mutex_lock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_lock %d",rtn), exit(1);
/* no space and this caller doesn't want to wait */
if ((tpool->cur_queue_size == tpool->max_queue_size) &&
tpool->do_not_block_when_full) {
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
return -1;
}
while( (tpool->cur_queue_size == tpool->max_queue_size) &&
(!(tpool->shutdown || tpool->queue_closed)) ) {
if ((rtn = pthread_cond_wait(&(tpool->queue_not_full),
&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_cond_wait %d",rtn), exit(1);
}
/* the pool is in the process of being destroyed */
if (tpool->shutdown || tpool->queue_closed) {
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
return -1;
}
/* allocate work structure */
if ((workp = (tpool_work_t *)malloc(sizeof(tpool_work_t))) == NULL)
perror("malloc"), exit(1);
workp->routine = routine;
workp->arg = arg;
workp->next = NULL;
printf("adder adding an item %d\n", workp->routine);
if (tpool->cur_queue_size == 0) {
tpool->queue_tail = tpool->queue_head = workp;
printf("adder queue == 0, waking all workers\n");
if ((rtn = pthread_cond_broadcast(&(tpool->queue_not_empty))) !=
0)
fprintf(stderr,"pthread_cond_signal %d",rtn), exit(1);;
} else {
tpool->queue_tail->next = workp;
tpool->queue_tail = workp;
}
tpool->cur_queue_size++;
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
return 1;
}
int tpool_destroy(tpool_t tpool,
int finish)
{
int i,rtn;
tpool_work_t *cur_nodep;
if ((rtn = pthread_mutex_lock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_lock %d",rtn), exit(1);
/* Is a shutdown already in progress? */
if (tpool->queue_closed || tpool->shutdown) {
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
return 0;
}
tpool->queue_closed = 1;
/* If the finish flag is set, wait for workers to
drain queue */
if (finish == 1) {
while (tpool->cur_queue_size != 0) {
if ((rtn = pthread_cond_wait(&(tpool->queue_empty),
&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_cond_wait %d",rtn), exit(1);
}
}
tpool->shutdown = 1;
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
/* Wake up any workers so they recheck shutdown flag */
if ((rtn = pthread_cond_broadcast(&(tpool->queue_not_empty))) != 0)
fprintf(stderr,"pthread_cond_broadcast %d",rtn), exit(1);
if ((rtn = pthread_cond_broadcast(&(tpool->queue_not_full))) != 0)
fprintf(stderr,"pthread_cond_broadcast %d",rtn), exit(1);
/* Wait for workers to exit */
for(i=0; i < tpool->num_threads; i++) {
if ((rtn = pthread_join(tpool->threads[i],NULL)) != 0)
fprintf(stderr,"pthread_join %d",rtn), exit(1);
}
/* Now free pool structures */
free(tpool->threads);
while(tpool->queue_head != NULL) {
cur_nodep = tpool->queue_head->next;
tpool->queue_head = tpool->queue_head->next;
free(cur_nodep);
}
free(tpool);
}
void *tpool_thread(void *arg)
{
tpool_t tpool = (tpool_t)arg;
int rtn;
tpool_work_t *my_workp;
for(;;) {
/* Check queue for work */
if ((rtn = pthread_mutex_lock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_lock %d",rtn), exit(1);
while ((tpool->cur_queue_size == 0) && (!tpool->shutdown)) {
printf("worker %d I'm sleeping again\n", pthread_self());
if ((rtn = pthread_cond_wait(&(tpool->queue_not_empty),
&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_cond_wait %d",rtn), exit(1);
}
sleep(5);
printf("worker %d I'm awake\n", pthread_self());
/* Has a shutdown started while i was sleeping? */
if (tpool->shutdown == 1) {
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
pthread_exit(NULL);
}
/* Get to work, dequeue the next item */
my_workp = tpool->queue_head;
tpool->cur_queue_size--;
if (tpool->cur_queue_size == 0)
tpool->queue_head = tpool->queue_tail = NULL;
else
tpool->queue_head = my_workp->next;
printf("worker %d dequeing item %d\n", pthread_self(), my_workp-
>next);
/* Handle waiting add_work threads */
if ((!tpool->do_not_block_when_full) &&
(tpool->cur_queue_size == (tpool->max_queue_size - 1)))
if ((rtn = pthread_cond_broadcast(&(tpool->queue_not_full))) !
= 0)
fprintf(stderr,"pthread_cond_broadcast %d",rtn), exit(1);
/* Handle waiting destroyer threads */
if (tpool->cur_queue_size == 0)
if ((rtn = pthread_cond_signal(&(tpool->queue_empty))) != 0)
fprintf(stderr,"pthread_cond_signal %d",rtn), exit(1);
if ((rtn = pthread_mutex_unlock(&(tpool->queue_lock))) != 0)
fprintf(stderr,"pthread_mutex_unlock %d",rtn), exit(1);
/* Do this work item */
(*(my_workp->routine))(my_workp->arg);
free(my_workp);
}
return(NULL);
}
그 다음으로 tpooltest.c 파일
********************************************************
* tpool.c --
*
* Example caller for thread pooling library
*/
#include
#include
#include "tpool.h"
char *s1[20]={ "STRING 0",
"STRING 1",
"STRING 2",
"STRING 3",
"STRING 4",
"STRING 5",
"STRING 6",
"STRING 7",
"STRING 8",
"STRING 9",
"STRING 10",
"STRING 11",
"STRING 12",
"STRING 13",
"STRING 14",
"STRING 15",
"STRING 16",
"STRING 17",
"STRING 18",
"STRING 19"};
void r1(char * printstring)
{
int i, x;
printf("%s START\n", printstring);
for (i = 0; i < 1000000; i++) {
x = x +i;
}
printf("%s DONE\n", printstring);
}
extern int
main(void)
{
extern char *s1[];
pthread_t t1,t2;
int i;
tpool_t test_pool;
tpool_init(&test_pool, 10, 20, 0);
sleep(5);
for ( i = 0; i < 5; i++) {
printf("tpool_add_work returned %d\n",
tpool_add_work(test_pool, r1, s1[i]));
}
printf("main all work queued\n");
tpool_destroy(test_pool, 1);
return 0;
}
댓글 달기