linker error when compiling an OpenCV 2.0 test code - c

I am trying to compile this C file to test if OpenCV will work correctly so I can do the OpenCV lab in Head First C book
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
cvNamedWindow("detector", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
if (frame == NULL)
{
printf("error: frame is null\n\n");
break;
}
cvShowImage("detector", frame);
char c = cvWaitKey(50);
if (c == 27)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("detector");
return 0;
}
When typing the command and adding the library
gcc libcv200.dll.a -I C:\OpenCV2.0\include\opencv\ .\intruder_detector.o -o .\intruder_detector
libcv200.dll.a and intruder_detector.o is in the same directory
I get this output
.\intruder_detector.o:intruder_detector.c:(.text+0xa97): undefined reference to `cvFree_'
.\intruder_detector.o:intruder_detector.c:(.text+0xb20): undefined reference to `cvFree_'
.\intruder_detector.o:intruder_detector.c:(.text+0xc4d): undefined reference to `cvGetRows'
.\intruder_detector.o:intruder_detector.c:(.text+0xc86): undefined reference to `cvGetCols'
.\intruder_detector.o:intruder_detector.c:(.text+0xca1): undefined reference to `cvReleaseMat'
.\intruder_detector.o:intruder_detector.c:(.text+0xe1f): undefined reference to `cvAddS'
.\intruder_detector.o:intruder_detector.c:(.text+0xe5f): undefined reference to `cvSeqSlice'
.\intruder_detector.o:intruder_detector.c:(.text+0xed0): undefined reference to `cvSetAdd'
.\intruder_detector.o:intruder_detector.c:(.text+0xf7e): undefined reference to `cvGetSeqElem'
.\intruder_detector.o:intruder_detector.c:(.text+0x107d): undefined reference to `cvEllipse'
.\intruder_detector.o:intruder_detector.c:(.text+0x10de): undefined reference to `cvInitFont'
.\intruder_detector.o:intruder_detector.c:(.text+0x11b1): undefined reference to `cvGetFileNodeByName'
.\intruder_detector.o:intruder_detector.c:(.text+0x1257): undefined reference to `cvGetFileNodeByName'
.\intruder_detector.o:intruder_detector.c:(.text+0x12df): undefined reference to `cvGetFileNodeByName'
.\intruder_detector.o:intruder_detector.c:(.text+0x1323): undefined reference to `cvGetFileNodeByName'
.\intruder_detector.o:intruder_detector.c:(.text+0x1336): undefined reference to `cvRead'
.\intruder_detector.o:intruder_detector.c:(.text+0x145b): undefined reference to `cvCreateSubdiv2D'
.\intruder_detector.o:intruder_detector.c:(.text+0x147f): undefined reference to `cvInitSubdivDelaunay2D'
.\intruder_detector.o:intruder_detector.c:(.text+0x1654): undefined reference to `cvCalcArrHist'
.\intruder_detector.o:intruder_detector.c:(.text+0x17d1): undefined reference to `cvAvg'
.\intruder_detector.o:intruder_detector.c:(.text+0x1802): undefined reference to `cvSum'
.\intruder_detector.o:intruder_detector.c:(.text+0x184d): undefined reference to `cvAvgSdv'
.\intruder_detector.o:intruder_detector.c:(.text+0x18ac): undefined reference to `cvReshape'
.\intruder_detector.o:intruder_detector.c:(.text+0x18c8): undefined reference to `cvReshape'
.\intruder_detector.o:intruder_detector.c:(.text+0x18dc): undefined reference to `cvPerspectiveTransform'
.\intruder_detector.o:intruder_detector.c:(.text+0x18fd): undefined reference to `cvGetElemType'
.\intruder_detector.o:intruder_detector.c:(.text+0x1917): undefined reference to `cvColorToScalar'
.\intruder_detector.o:intruder_detector.c:(.text+0x194d): undefined reference to `cvSet'
.\intruder_detector.o:intruder_detector.c:(.text+0x199c): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x19d3): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x1aea): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x1b1f): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x1bac): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x1c1e): undefined reference to `cvRandArr'
.\intruder_detector.o:intruder_detector.c:(.text+0x1d96): undefined reference to `cvCartToPolar'
.\intruder_detector.o:intruder_detector.c:(.text+0x1e6f): undefined reference to `cvCartToPolar'
.\intruder_detector.o:intruder_detector.c:(.text+0x1f02): undefined reference to `cvPow'
.\intruder_detector.o:intruder_detector.c:(.text+0x1f95): undefined reference to `cvPow'
.\intruder_detector.o:intruder_detector.c:(.text+0x2028): undefined reference to `cvPow'
.\intruder_detector.o:intruder_detector.c:(.text+0x20a5): undefined reference to `cvExp'
.\intruder_detector.o:intruder_detector.c:(.text+0x2122): undefined reference to `cvLog'
.\intruder_detector.o:intruder_detector.c:(.text+0x2156): undefined reference to `cvBoundingRect'
.\intruder_detector.o:intruder_detector.c:(.text+0x2186): undefined reference to `cvInvert'
.\intruder_detector.o:intruder_detector.c:(.text+0x2218): undefined reference to `cvConvexHull2'
.\intruder_detector.o:intruder_detector.c:(.text+0x2281): undefined reference to `cvMinAreaRect2'
.\intruder_detector.o:intruder_detector.c:(.text+0x22b0): undefined reference to `cvBoxPoints'
.\intruder_detector.o:intruder_detector.c:(.text+0x23ca): undefined reference to `cvFitLine'
.\intruder_detector.o:intruder_detector.c:(.text+0x247c): undefined reference to `cvFitLine'
.\intruder_detector.o:intruder_detector.c:(.text+0x24d9): undefined reference to `cvFitEllipse2'
.\intruder_detector.o:intruder_detector.c:(.text+0x2634): undefined reference to `cvTransform'
.\intruder_detector.o:intruder_detector.c:(.text+0x26c3): undefined reference to `cvHoughLines2'
.\intruder_detector.o:intruder_detector.c:(.text+0x2753): undefined reference to `cvHoughLines2'
.\intruder_detector.o:intruder_detector.c:(.text+0x27e3): undefined reference to `cvHoughLines2'
.\intruder_detector.o:intruder_detector.c:(.text+0x2846): undefined reference to `cvCreateMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x285f): undefined reference to `cvCreateMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x29e7): undefined reference to `cvFindFundamentalMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x29f3): undefined reference to `cvReleaseMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x29ff): undefined reference to `cvReleaseMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x2a44): undefined reference to `cvFindChessboardCorners'
.\intruder_detector.o:intruder_detector.c:(.text+0x2cad): undefined reference to `cvCalibrateCamera2'
.\intruder_detector.o:intruder_detector.c:(.text+0x2f1a): undefined reference to `cvCalibrateCamera2'
.\intruder_detector.o:intruder_detector.c:(.text+0x30f7): undefined reference to `cvFindExtrinsicCameraParams2'
.\intruder_detector.o:intruder_detector.c:(.text+0x32f8): undefined reference to `cvFindExtrinsicCameraParams2'
.\intruder_detector.o:intruder_detector.c:(.text+0x3338): undefined reference to `cvRodrigues2'
.\intruder_detector.o:intruder_detector.c:(.text+0x3351): undefined reference to `cvRodrigues2'
.\intruder_detector.o:intruder_detector.c:(.text+0x3691): undefined reference to `cvProjectPoints2'
.\intruder_detector.o:intruder_detector.c:(.text+0x382c): undefined reference to `cvProjectPoints2'
.\intruder_detector.o:intruder_detector.c:(.text+0x38bb): undefined reference to `cvUndistort2'
.\intruder_detector.o:intruder_detector.c:(.text+0x38fa): undefined reference to `cvGetRawData'
.\intruder_detector.o:intruder_detector.c:(.text+0x3a2d): undefined reference to `cvGetRawData'
.\intruder_detector.o:intruder_detector.c:(.text+0x3b56): undefined reference to `cvCalcEMD2'
.\intruder_detector.o:intruder_detector.c:(.text+0x3ba5): undefined reference to `cvCreateMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x3c7e): undefined reference to `cvKMeans2'
.\intruder_detector.o:intruder_detector.c:(.text+0x3c8a): undefined reference to `cvReleaseMat'
.\intruder_detector.o:intruder_detector.c:(.text+0x3cdb): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x3cf1): undefined reference to `cvCreateGraphScanner'
.\intruder_detector.o:intruder_detector.c:(.text+0x3d37): undefined reference to `cvFree_'
.\intruder_detector.o:intruder_detector.c:(.text+0x3d80): undefined reference to `cvError'
.\intruder_detector.o:intruder_detector.c:(.text+0x3d97): undefined reference to `cvAlloc'
.\intruder_detector.o:intruder_detector.c:(.text+0x3ddd): undefined reference to `cvReleaseGraphScanner'
.\intruder_detector.o:intruder_detector.c:(.text+0x3e1a): undefined reference to `cvGetElemType'
.\intruder_detector.o:intruder_detector.c:(.text+0x3e34): undefined reference to `cvColorToScalar'
.\intruder_detector.o:intruder_detector.c:(.text+0x3e86): undefined reference to `cvLine'
.\intruder_detector.o:intruder_detector.c:(.text+0x3eaf): undefined reference to `cvGetElemType'
.\intruder_detector.o:intruder_detector.c:(.text+0x3ec9): undefined reference to `cvColorToScalar'
.\intruder_detector.o:intruder_detector.c:(.text+0x3f1b): undefined reference to `cvCircle'
.\intruder_detector.o:intruder_detector.c:(.text+0x3f47): undefined reference to `cvGetElemType'
.\intruder_detector.o:intruder_detector.c:(.text+0x3f61): undefined reference to `cvColorToScalar'
.\intruder_detector.o:intruder_detector.c:(.text+0x3fd4): undefined reference to `cvEllipse'
.\intruder_detector.o:intruder_detector.c:(.text+0x4002): undefined reference to `cvGetElemType'
.\intruder_detector.o:intruder_detector.c:(.text+0x401c): undefined reference to `cvColorToScalar'
.\intruder_detector.o:intruder_detector.c:(.text+0x407e): undefined reference to `cvPolyLine'
.\intruder_detector.o:intruder_detector.c:(.text+0x430d): undefined reference to `cvNamedWindow'
.\intruder_detector.o:intruder_detector.c:(.text+0x4317): undefined reference to `cvCreateCameraCapture'
.\intruder_detector.o:intruder_detector.c:(.text+0x4327): undefined reference to `cvQueryFrame'
.\intruder_detector.o:intruder_detector.c:(.text+0x4353): undefined reference to `cvShowImage'
.\intruder_detector.o:intruder_detector.c:(.text+0x435d): undefined reference to `cvWaitKey'
.\intruder_detector.o:intruder_detector.c:(.text+0x4375): undefined reference to `cvReleaseCapture'
.\intruder_detector.o:intruder_detector.c:(.text+0x4381): undefined reference to `cvDestroyWindow'
collect2.exe: error: ld returned 1 exit status
So I tried all the other libraries in C:\OpenCV2.0\lib folder which contains the following libraries
-a---- 10/1/2009 6:02 AM 435896 libcv200.dll.a
-a---- 10/1/2009 6:10 AM 465136 libcvaux200.dll.a
-a---- 10/1/2009 5:58 AM 526158 libcxcore200.dll.a
-a---- 10/1/2009 6:16 AM 150786 libcxts200.dll.a
-a---- 10/1/2009 6:06 AM 138242 libhighgui200.dll.a
-a---- 10/1/2009 6:07 AM 375380 libml200.dll.a
I don't know if I'm compiling the code correctly or I need some other libraries.
I tried searching if someone got the same issue, but I didn't find any solution.
Can anyone help me?

Related

Trying to run simple graphics program in c using command prompt

This is the following program.
#include <graphics.h>
int main(void)
{
drawRect(50,100,200,150);
drawLine(50,100,150,25);
drawLine(150,25,250,100);
drawRect(130,190,40,60);
drawRect(70,195,40,30);
drawRect(190,195,40,30);
drawRect(70,125,40,30);
drawRect(190,125,40,30);
return 0;
}
and following is the error
C:\Users\Balavardhan\Desktop\New folder\c language>gcc z.c -o z.exe
z.c: In function 'main':
z.c:4:6: warning: implicit declaration of function 'drawRect'; did you mean 'drawpoly'? [-Wimplicit-function-declaration]
drawRect(50,100,200,150);
^~~~~~~~
drawpoly
z.c:5:6: warning: implicit declaration of function 'drawLine'; did you mean 'drawpoly'? [-Wimplicit-function-declaration]
drawLine(50,100,150,25);
^~~~~~~~
drawpoly
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x2e): undefined reference to `drawRect'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x52): undefined reference to `drawLine'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x76): undefined reference to `drawLine'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x9a): undefined reference to `drawRect'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0xbe): undefined reference to `drawRect'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0xe2): undefined reference to `drawRect'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x106): undefined reference to `drawRect'
C:\Users\BALAVA~1\AppData\Local\Temp\ccMnl0ZM.o:z.c:(.text+0x12a): undefined reference to `drawRect'
collect2.exe: error: ld returned 1 exit status
Can anyone tell me how can I solve this problem?

CUDD package : Undefined reference during compilation

I am learning CUDD package for research purposes. I have got one sample code from which I have tried to learn the basic functionalities. But I am getting error during compilation.
I have already set the paths for the header.
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include "cudd.h"
#include "util.h"
void print_dd(DdManager *gbm, DdNode *dd, int n, int pr)
{
printf("Ddmanager nodes : %ld \n",Cudd_ReadNodeCount(gbm));
printf("Ddmanager vars : %d \n",Cudd_ReadSize(gbm));
printf("Ddmanager reorderings :%d\n",Cudd_ReadReorderings(gbm));
printf("DdManager memory % ld",Cudd_ReadMemoryInUse(gbm));
Cudd_PrintDebug(gbm,dd,n,pr);
}
void write_dd(DdManager *gbm, DdNode *dd, char * filename)
{
FILE *outfile;
outfile=fopen(filename,"w");
DdNode **ddnodearray=(DdNode **)malloc(sizeof(DdNode*));
ddnodearray[0]=dd;
Cudd_DumpDot(gbm,1,ddnodearray,NULL,NULL,outfile);
free(ddnodearray);
fclose(outfile);
}
int main(int argc, char *argv[])
{
DdManager *gbm;
char filename[30];
gbm=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
DdNode *bdd=Cudd_bddNewVar(gbm);
Cudd_Ref(bdd);
bdd=Cudd_BddToAdd(gbm,bdd);
print_dd(gbm,bdd,2,4);
sprintf(filename,"./bdd/graph.dot");
write_dd(gbm,bdd,filename);
Cudd_Quit(gbm);
return 0;
}
I am getting some error during compilation.
gcc -I /home/subhadip/cudd-3.0.0 -I /home/subhadip/cudd-3.0.0/util -I /home/subhadip/cudd-3.0.0/cudd transfer1.c /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAPI.o): In function `Cudd_ExpectedUsedSlots':
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1835: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1844: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1850: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddCache.o): In function `cuddCacheProfile':
/home/subhadip/cudd-3.0.0/cudd/cuddCache.c:816: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_LdblCountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:729: undefined reference to `powl'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o): In function `EpdNormalizeDecimal':
/home/subhadip/cudd-3.0.0/epd/epd.c:834: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/epd/epd.c:834: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o):/home/subhadip/cudd-3.0.0/epd/epd.c:452: more undefined references to `pow' follow
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `cuddAnnealing':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
collect2: error: ld returned 1 exit status
I have tried to statically link the libraries but the there is a problem. How can I fix it?
You compiled cudd and generated a static library. Now you need to link with it:
gcc .. <other options> ... transfer1.c /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1
Note that the order of files matter.
I can guess that for C++ support you have to link with cplusplus/.libs/libobj.a and for dddmp support you need symbols exported in dddmp/.libs/libdddmp.a.
After using the above solution, if the error still persists,
For me, I have not made the folder named 'bdd' in the proper location for the code line:
sprintf(filename, "./bdd/graph.dot");
Now, it is executing for me.

failing on running coffee file system example on Wismote in Contiki

I want to test an example of cfs Contiki on Wismote. I used the example here:
Coffee filesystem example
This example works well on sky mote. when I want to implement on Wismote I change the target to Wismote and here is the makefile :
CONTIKI_PROJECT = [project_name]
all: $(CONTIKI_PROJECT)
#UIP_CONF_IPV6=1
CONTIKI_WITH_RIME = 1 CFLAGS =-DUIP_CONF_IPV6
MODULES += core/net/ipv6/multicast
ifeq ($(TARGET),avr-raven)
COFFEE_FILES = 4
endif
CONTIKI =../../../
include $(CONTIKI)/Makefile.include
After compiling, I get this error message :
/usr/local/msp430/bin/../lib/gcc/msp430/4.7.0/../../../../msp430/bin/ld: cfstest.wismote section .data' will not fit in regionrom'
/usr/local/msp430/bin/../lib/gcc/msp430/4.7.0/../../../../msp430/bin/ld: section .vectors loaded at [0000ff80,0000ffff] overlaps section .data loaded at [0000fe82,0000ff81]
/usr/local/msp430/bin/../lib/gcc/msp430/4.7.0/../../../../msp430/bin/ld: region rom' overflowed by 2 bytes
contiki-wismote.a(cfs-coffee.o): In functioncfs_coffee_get_protected_mem':
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pwrite'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_erase'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pwrite'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pread'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pwrite'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to xmem_pwrite'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference toxmem_pwrite'
/home/user/contiki/examples/mySim/Dscv/../../..//core/cfs/cfs-coffee.c:1369: undefined reference to `xmem_pwrite'
collect2: error: ld returned 1 exit status
rm cfstest.co obj_wismote/contiki-wismote-main.o
make: *** [cfstest.wismote] Error 1
Process returned error code 2
I checked core/cfs/cfs-coffee.c to see the code in line 1369, but as you can see in cfs-coffee.c, there was not such a line.
Does anyone has any idea to solve the problem?

Undefined reference error after using Makefile

I wrote a makefile to link all the .c files that i wanted to.But then again i get errors of undefined reference.The code for the makefile is:
FILES.o=set.o hash.o nfa.o printnfa.o input.o terp.o dfa.o minimize.o defnext.o print_ar.o pairs.o squash.o print.o assort.o prnt.o printv.o bintoasc.o ferr.o onferr.o fputstr.o pchar.o driver.o searchenv.o hashadd.o
PROGRAM= lexer
all: ${PROGRAM}
${PROGRAM}: ${FILES.o}
${CC} -o $# ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
But still it leads to undefined errors like :
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':(.text+0x20): undefined reference to `main'
nfa.o: In function `parse_err':
nfa.c:(.text+0x21): undefined reference to `Actual_lineno'
nfa.o: In function `save':
nfa.c:(.text+0x2d1): undefined reference to `Lineno'
nfa.o: In function `advance':
nfa.c:(.text+0x8b4): undefined reference to `esc'
nfa.o: In function `rule':
nfa.c:(.text+0xae1): undefined reference to `Unix'
nfa.o: In function `term':
nfa.c:(.text+0xfbd): undefined reference to `Unix'
nfa.c:(.text+0x10a2): undefined reference to `Unix'
nfa.o: In function `thompson':
nfa.c:(.text+0x1355): undefined reference to `CLEAR_STACK'
nfa.c:(.text+0x13ab): undefined reference to `Verbose'
nfa.c:(.text+0x13d3): undefined reference to `printf_nfa'
nfa.c:(.text+0x13d9): undefined reference to `Verbose'
input.o: In function `get_expr':
input.c:(.text+0x13): undefined reference to `Input_buf'
input.c:(.text+0x20): undefined reference to `Verbose'
input.c:(.text+0x2b): undefined reference to `Actual_lineno'
input.c:(.text+0x52): undefined reference to `Actual_lineno'
input.c:(.text+0x7a): undefined reference to `Actual_lineno'
input.c:(.text+0x83): undefined reference to `Actual_lineno'
input.c:(.text+0x8a): undefined reference to `Input_buf'
input.c:(.text+0x93): undefined reference to `Input_buf'
input.c:(.text+0xe2): undefined reference to `Ifile'
input.c:(.text+0x10c): undefined reference to `Verbose'
input.c:(.text+0x11c): undefined reference to `Input_buf'
input.c:(.text+0x136): undefined reference to `Input_buf'
dfa.o: In function `dfa':
dfa.c:(.text+0x69): undefined reference to `Verbose'
dfa.c:(.text+0x1c6): undefined reference to `Verbose'
dfa.c:(.text+0x215): undefined reference to `Verbose'
dfa.o: In function `get_unmarked':
dfa.c:(.text+0x3a8): undefined reference to `Verbose'
minimize.o: In function `init_groups':
minimize.c:(.text+0x28c): undefined reference to `Verbose'
minimize.o:minimize.c:(.text+0x550): more undefined references to `Verbose' follow
print.o: In function `pdriver':
print.c:(.text+0x483): undefined reference to `No_lines'
print.c:(.text+0x4eb): undefined reference to `No_lines'
print.c:(.text+0x4f6): undefined reference to `Input_file_name'
print.c:(.text+0x585): undefined reference to `No_lines'
collect2: error: ld returned 1 exit status
make: *** [lexer] Error 1
All the undefined references are however present in 2 header files :1.stack.h 2.global.h..Still the errors.please help!
The global.h file i am using is:
#ifndef __GLOBAL_H
#define __GLOBAL_H
#include <stdio.h>
#ifdef ALLOC
# define CLASS
# define I(x) x
#else
# define CLASS extern
# define I(x)
#endif
#define MAXINP 2048
CLASS int Verbose I(=0);
CLASS int No_lines I(=0);
CLASS int Unix I(=0);
CLASS int Public I(=0);
CLASS char *Template I(="lex.par");
CLASS int Actual_lineno I(=1);
CLASS int Lineno I(=1);
CLASS char Input_buf[MAXINP]; //line buffer for input
CLASS char *Input_file_name; //Input file name
CLASS FILE *Ifile; //Input Stream
CLASS FILE *ofile; //Output Stream
#endif
Your problem isn't related to the Makefile per se. The header-only include file global.h contains declarations of variables. These declarations have to be turned into actual definitions in one compilation unit, so that they have space for them allocated in one of your object files.
The way your header file is designed, the definition of the variable ALLOC determines whether the variables are just declared or defined.
The regular include without ALLOC yields for example:
extern int Verbose;
The extern keyword indicates that the variable Verbose is not defined. No memory is allocated for it (and it therefore can't have an initialiser) and that it is probably defined in another object file.
When ALLOC is defined, the declaration becomes a definition with initialisation:
int Verbose = 0;
Pick one of the files that include global.h and define ALLOC before including it, for example:
input.c
#define ALLOC
#include "global.h"
You should then have the symbol Verbose defined as an int with initial value 0 in global.o:
> nm input.o | grep Verbose
0000000000000000 B Verbose
> nm set.o | grep Verbose
U Verbose
(nm is a Linux utility that lists the symbols in an object file. Windows has dumpbin.)
The U in the object file without ALLOC means that the symbol is undefined, i.e. referenced but not defined in this object file. The B in input.o denotes the section where the symol is defined. When you link, you can have many Us, but for each symbol that is undefined in an object file, you also need one object file where the symbol is defined.
you should add header files in all files which are contained in makefile...
otherwise those files will not able to recognize those variables

C sockets error

For some reason this line of code is giving me quite a problem.
struct socketaddr_in clientaddr;
The error message is:
tiny.c:23:24: error: storage size of ‘clientaddr’ isn’t known
If I remove that line of code I get the following error message:
s2s2#s2s2-ThinkPad-T61:~/Documents/Cprogramming/web_server$ make
gcc -std=gnu99 -O2 -lpthread -lrt -o server tiny.c csapp.c
/tmp/ccVxw07i.o: In function `Pthread_create':
csapp.c:(.text+0x7e5): undefined reference to `pthread_create'
/tmp/ccVxw07i.o: In function `Pthread_cancel':
csapp.c:(.text+0x805): undefined reference to `pthread_cancel'
/tmp/ccVxw07i.o: In function `Pthread_join':
csapp.c:(.text+0x825): undefined reference to `pthread_join'
/tmp/ccVxw07i.o: In function `Pthread_detach':
csapp.c:(.text+0x845): undefined reference to `pthread_detach'
/tmp/ccVxw07i.o: In function `Sem_init':
csapp.c:(.text+0x895): undefined reference to `sem_init'
/tmp/ccVxw07i.o: In function `P':
csapp.c:(.text+0x8b5): undefined reference to `sem_wait'
/tmp/ccVxw07i.o: In function `V':
csapp.c:(.text+0x8d5): undefined reference to `sem_post'
/tmp/ccVxw07i.o: In function `Pthread_once':
csapp.c:(.text+0x881): undefined reference to `pthread_once'
collect2: ld returned 1 exit status
make: *** [webServer-gcc] Error 1
Here are links to the csapp.c and csapp.h files.
Thanks for all the help.
tiny.c:23:24: error: storage size of ‘clientaddr’ isn’t known
There's a reason you need to declare structs as struct structname instancename in C - that's so that the C compiler knows how much memory to allocate - and possibly how to align that data, etc.
This is the C compiler's way of telling you no such struct socketaddr_in exists - it'd be sockaddr_in.
A common way to work around the naming of structs in this way is to define them like this:
typedef struct _struct_name
{
/* ... */
} structname;
then structname can be used as a type without the struct qualifier. You don't have to do this on the definition of the struct, either, you could do it later.
So, the short answer is socketaddr_in doesn't exist as a struct in POSIX - it's sockaddr_in.

Resources