Linux Linking Errors

Linux Linking Errors

Summary

Linux Linking Errors

Synopsis

When linking the application, the following error is seen:
../LINUX/int_lib/liblmgr.a(l_unixmt.o)(.text+0x1cc): In function `l_mt_heartbeat':: undefined reference to `pthread_create'../LINUX/int_lib/liblmgr.a(l_unixmt.o)(.text+0x427): In function `l_mt_free':: undefined reference to `pthread_join'collect2: ld returned 1 exit status.

Discussion

This is caused by missing the "-lpthread" link flag.Adding the "-lpthread" should resolve the problem.
Below is an example using our lmflex sample application:
Makefile :Line1: lmflex: $(SRCDIR)/lmflex.c $(SRCDIR)/lm_code.h $(CLIENTLIB) lmstrip lm_new.oLine2: $(MAKE) lm_new.oLine3: $(CC) $(CFLAGS) $(SRCDIR)/lmflex.cLine4: $(CC) -o lmflex lmflex.o lm_new.o $(CLIENTLIB) $(XTRALIB) $(THREADLIB)Line5: rm lmflex.oLine6: $(STRIP) lmflexLine7: ./lmstrip lmflexLine8: rm -f lm_new.o. After you type "make lmflex" from the shell, you will see the following lines. As you can see Line#3 and Line#4 below refers to the makefile file Line#3 and Line#4 above.Line3: cc -c -g -I../machind -I. -DRELEASE_VERSION -DSUNOS5 -DLM_INTERNAL ../machind/lmflex.cLine4: cc -o lmflex lmflex.o lm_new.o liblmgr.a libcrvs.a libsb.a -lsocket -lnsl -lintl -lsocket -lnsl -lintl -lpthread -lpthread.
Was this article helpful? Yes No
No ratings
Version history
Revision #:
1 of 1
Last update:
‎Nov 07, 2007 06:35 PM
Updated by: