Keep's telling it's an undefined reference, even though it's clearly not.
The code belows imports a C++ file. it compiles fine, but whenever I call a function contained within it, that's when it fails at the linking stage.
C:/Program Files/BlitzMax/ARPG/.bmx/AI.bmx.gui.debug.win32.o(code+0x185): undefined reference to `CreateLine'
C:/Program Files/BlitzMax/ARPG/.bmx/AI.bmx.gui.debug.win32.o(code+0x1ac): undefined reference to `CreateLine'
Referencing the two times I called the function in the test code below..
BlitzMax Code.
C++ Code, call it "Lines2d.cpp"
The code belows imports a C++ file. it compiles fine, but whenever I call a function contained within it, that's when it fails at the linking stage.
C:/Program Files/BlitzMax/ARPG/.bmx/AI.bmx.gui.debug.win32.o(code+0x185): undefined reference to `CreateLine'
C:/Program Files/BlitzMax/ARPG/.bmx/AI.bmx.gui.debug.win32.o(code+0x1ac): undefined reference to `CreateLine'
Referencing the two times I called the function in the test code below..
BlitzMax Code.
Import "Line2D.cpp" Public Extern "win32" Function CreateLine:Int( x1#,y1#,x2#,y2# )="CreateLine" Function SetLine( line,x1#,y1#,x2#,y2# ) Function LineCast:Int( line1,line2,result ) Function ResultX:Int(result) Function ResultY:Int(result) Function CreateResult:Int() End Extern Graphics 640,480,0 Local x1#,y1#,x2#,y2# x1=20 y1=20 Local lin1,lin2 lin1 = createLine( x1,y1,x2,y2 ) lin2 = createLine( 320,0,325,480 ) If lin1=0 RuntimeError "Line was not created." Repeat Cls x2=MouseX() y2=MouseY() DrawLine x1,y1,x2,y2 DrawLine 320,0,325,480 Flip Until KeyDown(1)
C++ Code, call it "Lines2d.cpp"
class XPOINT { public: float x, y; }; class XLINE { public: XPOINT o, p; float m; float c; }; float min( float v1,float v2 ) { if(v1<v2) return v2; return v1; } float max( float v1,float v2) { if(v1>v2) return v1; return v2; } XLINE CreateLine( float x1,float y1,float x2,float y2){ XLINE out; out.o.x=x1; out.o.y=y1; out.p.x=x2; out.p.y=y2; return out; } void SetLine( XLINE &l,float x1,float y1,float x2,float y2){ l.o.x=x1; l.o.y=y1; l.p.x=x2; l.p.y=y2; } XPOINT * CreateResult(){ return( new XPOINT); } float ResultX( XPOINT *i){ return i->x; } float ResultY( XPOINT *i){ return i->y; } int LineCast( XLINE &a, XLINE &b, XPOINT *i ) { // null width lines cannot intercept if ( (a.p.x == a.o.x) || (b.p.x == b.o.x) ) { return false; } // calculate gradients a.m = (a.p.y - a.o.y) / (a.p.x - a.o.x); b.m = (b.p.y - b.o.y) / (b.p.x - b.o.x); // parallel lines can't intercept if (a.m == b.m) { return false; } // calculate axis intersect values a.c = a.o.y - (a.m * a.o.x); b.c = b.o.y - (b.m * b.o.x); // calculate x point of intercept i->x = (b.c - a.c) / (a.m - b.m); // is intersection point in segment if ( i->x < min(a.o.x, a.p.x) || i->x > max(a.o.x, a.p.x) ) { return false; } if ( i->x < min(b.o.x, b.p.x) || i->x > max(b.o.x, b.p.x) ) { return false; } // calculate y point of intercept i->y = (a.m * i->x) + a.c; // points intercept return true; };