<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Using Dev-Cpp to compile static library</title>
		<link>http://www.allegro.cc/forums/view/587037</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 15 Aug 2006 05:29:09 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>After a bit of a vacation, I decided to return to game programming. I am using Bloodshed&#39;s Dev-Cpp ide for simplicity. I entered and compiled a program, but when linking, I get the following errors:</p><p>&quot;[linker error] undefined reference to &#39;backward&#39; (2x)<br />[linker error] undefined reference to &#39;rans&#39;<br />[linker error] undefined reference to &#39;testprintf-ex&#39;&quot;.</p><p>I selected project &gt; project options then parameters, under compiler I had &quot;-DALLEGRO_STATICLINK&quot;, under C++ compiler I had &quot;_DALLEGRO_STATICLINK&quot;, and under linker, I had (in this order) &quot;-lalleg_s -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound&quot;.</p><p>To create the project, I selected file, new project, multimedia and allegro static library, the programming language was set to C. I was able to compile and link with no problems before, but I cannot remember how. What did I miss? I am using allegro 4.2.0. Thanks in advance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob Keane)</author>
		<pubDate>Mon, 14 Aug 2006 21:53:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I don&#39;t know what backward is, rans... what&#39;s that. Is that a misspelling of rand()? And testprintf-ex should be textprintf_ex.</p><p>[edit] Can you post the source?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Mon, 14 Aug 2006 21:58:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[Its a long one. I am trying to adapt Game Programming All In One's tank war to suit my needs. I have not added my changes yet.<br />
<br />
Source(main.c):<br />
[code]<br />
/* Sea War By Bob Keane My first attempt at programming a game. This game is<br />
based on the Game Programming All In One sample game Tank War. Changes include multiple enemy ships,<br />
A storyline and random ship movement. I will change as necessary when possible. <br />
*/<br />
<br />
#include &quot;seawar.h&quot;<br />
<br />
// drawtank function. construct the tank using drawing functions.<br />
void drawtank(int num)<br />
{<br />
     int x = tanks[num].x;<br />
     int y = tanks[num].y;<br />
     int dir = tanks[num].dir;<br />
     <br />
     //draw tank body and turret.<br />
     <br />
     rectfill(screen, x - 11, y - 11, x + 11, y + 11, tanks[num].color);<br />
     rectfill(screen, x - 6, y - 6, x + 6, y + 6, 7);<br />
     <br />
     // Draw the treads based on orientation.<br />
     <br />
     if (dir == 0 || dir ==2)<br />
     {<br />
             rectfill(screen, x - 16, y - 16, x - 11, y + 16, 8);<br />
             rectfill(screen, x+11, y-16, x+16, y+16, 8);<br />
             }<br />
     else<br />
     if (dir == 1 || dir == 3)<br />
     {<br />
             rectfill(screen, x-16, y-16, x+16, y-11, 8);<br />
             rectfill(screen, x-16, y+16, x+16, y+11, 8);<br />
             }<br />
     <br />
     // Draw the turret based on direction<br />
     switch (dir)<br />
     {<br />
            case 0:<br />
                 rectfill(screen, x-1, y, x+1, y-16, 8);<br />
            break;<br />
            case 1:<br />
                 rectfill(screen, x, y-1, x+16, y+1, 8);<br />
            break;<br />
            case 2:<br />
                 rectfill(screen, x-1, y, x+1, y+16, 8);<br />
            break;<br />
            case 3:<br />
                 rectfill(screen, x, y-1, x-16, y+1, 8);<br />
            break;<br />
            }<br />
}<br />
<br />
// Erasetank function. erase the tank using rectfill.<br />
void erasetank(int num)<br />
{<br />
     <br />
     // calculate box to encompass the tank.<br />
     int left = tanks[num].x - 17;<br />
     int top = tanks[num].y - 17;<br />
     int right = tanks[num].x + 17;<br />
     int bottom = tanks[num].y + 17;<br />
     <br />
     // erase the tank.<br />
     rectfill(screen, left, top, right, bottom, 0);<br />
}<br />
<br />
// movetank function. move the tank in the current direction.<br />
void movetank(int num)<br />
{<br />
     int dir = tanks[num].dir;<br />
     int speed = tanks[num].speed;<br />
     <br />
     // update the tank's position based on direction.<br />
     switch (dir)<br />
     {<br />
            case 0:<br />
                 tanks[num].y-= speed;<br />
            break;<br />
            case 1:<br />
                 tanks[num].x+= speed;<br />
            break;<br />
            case 2:<br />
                 tanks[num].y+= speed;<br />
            break;<br />
            case 3:<br />
                 tanks[num].x-= speed;<br />
                 }<br />
            <br />
            // keep the tank inside the screen.<br />
            <br />
            if (tanks[num].x &gt; SCREEN_W-22)<br />
            {<br />
                             tanks[num].x = SCREEN_W - 22;<br />
                             tanks[num].speed = 0;<br />
                             }<br />
            <br />
            if (tanks[num].x &lt; 22)<br />
            {<br />
                             tanks[num].x = 22;<br />
                             tanks[num].speed = 0;<br />
                             }<br />
            <br />
            if (tanks[num].y &gt; SCREEN_H-22)<br />
            {<br />
                             tanks[num].y =SCREEN_H-22;<br />
                             tanks[num].speed = 0;<br />
                             }<br />
                             <br />
            if (tanks[num].y &lt; 22)<br />
            {<br />
                             tanks[num].y = 22;<br />
                             tanks[num].speed = 0;<br />
                             }<br />
            <br />
}<br />
<br />
// explode function. Display random boxes to simulate an explosion.<br />
void explode(int num, int x, int y)<br />
{<br />
     int n;<br />
     <br />
     //retrieve the location of the enemy tank<br />
     int tx = tanks[!num].x;<br />
     int ty = tanks[!num].y;<br />
     <br />
     // Is bullet inside the boundary of the enemy tank?<br />
     if (x &gt; tx-16 &amp;&amp; x &lt; tx+16 &amp;&amp; y &gt; ty-16 &amp;&amp; y &lt; ty+16)<br />
     score(num);<br />
     <br />
     // Draw some random circles for the &quot;explosion&quot;<br />
     for (n = 0; n &lt; 10; n++)<br />
     {<br />
         rectfill(screen, x-16, y-16, x+16, y+16, rand() % 16);<br />
         rest(1);<br />
         }<br />
         <br />
     // Clear the field of debris<br />
     rectfill(screen, x-16, y-16, x+16, y+16, 0);<br />
     <br />
}<br />
<br />
// updatebullet function Update the position of the bullet.<br />
void updatebullet(int num)<br />
{<br />
     int x = bullets[num].x;<br />
     int y = bullets[num].y;<br />
     <br />
     if (bullets[num].alive)<br />
     {<br />
                            // erase bullet.<br />
                            rect(screen, x-1, y-1, x+1, y+1, 0);<br />
                            <br />
                            // move bullet<br />
                            bullets[num].x += bullets[num].xspd;<br />
                            bullets[num].y += bullets[num].yspd;<br />
                            x = bullets[num].x;<br />
                            y = bullets[num].y;<br />
                            <br />
                            // Stay within the screen.<br />
                            if (x&lt;5 || x&gt; SCREEN_W-5 || y&lt;20 || y&gt; SCREEN_H-5)<br />
                            {<br />
                                    bullets[num].alive = 0;<br />
                                    return;<br />
                                    }<br />
                                    <br />
                            // draw bullet<br />
                            x = bullets[num].x;<br />
                            y = bullets[num].y;<br />
                            rect(screen, x-1, y-1, x+1, y+1, 4);<br />
                            <br />
                            // look for a hit<br />
                            if (getpixel(screen, bullets[num].x, bullets[num].y))<br />
                            {<br />
                                                 bullets[num].alive = 0;<br />
                                                 explode(num, x, y);<br />
                                                 }<br />
                            <br />
                            // print the bullet's position.<br />
                            textprintf_ex(screen, font, SCREEN_W/2-50,1,2,-1,&quot;B1 %-3dx%-3d B2 %-3dx-3d&quot;,bullets[0].x, bullets[0].y, bullets[1].x,bullets[1].y);<br />
                            <br />
                            }<br />
}<br />
<br />
// checkpath function check to see if a point on the screen is black.<br />
int checkpath(int x1, int y1, int x2, int y2, int x3, int y3)<br />
{<br />
    if (getpixel(screen, x1, y1) || getpixel(screen, x2, y2) || getpixel(screen, x3, y3))<br />
    return 1;<br />
    else<br />
    return 0;<br />
}<br />
<br />
// clearpath function verify that the tank can move in thte current direction<br />
void clearpath(int num)<br />
{<br />
     // shortcut vars<br />
     int dir = tanks[num].dir;<br />
     int speed = tanks[num].speed;<br />
     int x = tanks[num].x;<br />
     int y = tanks[num].y;<br />
     <br />
     switch (dir)<br />
     {<br />
            // check pixels north<br />
            case 0:<br />
                 if (speed &gt; 0)<br />
                 {<br />
                           if (checkpath(x-16, y-20, x, y-20, x+16, y-20))<br />
                           tanks[num].speed = 0;<br />
                           }<br />
                else<br />
                //if reverse direction, check south<br />
                if (checkpath(x-16, y+20, x, y+20,  x+16, y+20))<br />
                tanks[num].speed = 0;<br />
               break;<br />
               <br />
               // check pixels east<br />
           case 1:<br />
                if (speed &gt; 0)<br />
                {<br />
                          if (checkpath(x+20, y-16, x+20, y, x+20, y+16))<br />
                          tanks[num].speed = 0;<br />
                          }<br />
                else<br />
                // if reverse dir, check west<br />
                if (checkpath(x-20, y-16, x-20, y, x-20, y+16))<br />
                tanks[num].speed = 0;<br />
           break;<br />
           <br />
           // Check pixels south<br />
           case 2:<br />
                if (speed &gt; 0)<br />
                {<br />
                          if (checkpath(x-16, y-20, x, y-20, x+16, y-20))<br />
                          tanks[num].speed = 0;<br />
                          }<br />
                          <br />
                else<br />
                // if reverse direction, check north<br />
                if (checkpath(x-16, y-20, x, y-20, x+16, y-20))<br />
                tanks[num].speed = 0;<br />
           break;<br />
           <br />
           //check pixels west<br />
           case 3:<br />
                if (speed &gt; 0)<br />
                {<br />
                          if (checkpath(x-20, y-16, x-20, y, x-20, y+16))<br />
                          tanks[num].speed = 0;<br />
                          }<br />
                else<br />
                // if reverse dir, check east<br />
                if (checkpath(x+20, y-16, x+20, y, x+20, y+16))<br />
                tanks[num].speed = 0;<br />
           break;<br />
           }<br />
}<br />
<br />
// Fireweapon function configure a bullet's direction and speed and activate it.<br />
void fireweapon(int num)<br />
{<br />
     int x = tanks[num].x;<br />
     int y = tanks[num].y;<br />
     <br />
     // ready to fire again?<br />
     if (!bullets[num].alive)<br />
     {<br />
                             bullets[num].alive = 1;<br />
                             <br />
                             //fire weaponin direction tank is facing<br />
                             switch (tanks[num].dir)<br />
                             {<br />
                                    // north<br />
                                    case 0:<br />
                                         bullets[num].x = x;<br />
                                         bullets[num].y = y-22;<br />
                                         bullets[num].xspd = 0;<br />
                                         bullets[num].yspd = -BULLETSPEED;<br />
                                    break;<br />
                                    <br />
                                    //east<br />
                                    case 1:<br />
                                         bullets[num].x = x+22;<br />
                                         bullets[num].y = y;<br />
                                         bullets[num].xspd = BULLETSPEED;<br />
                                         bullets[num].yspd = 0;<br />
                                    break;<br />
                                    <br />
                                    //south<br />
                                    case 2:<br />
                                         bullets[num].x = x;<br />
                                         bullets[num].y = y+22;<br />
                                         bullets[num].xspd = 0;<br />
                                         bullets[num].yspd = BULLETSPEED;<br />
                                    break;<br />
                                    <br />
                                    //west<br />
                                    case 3:<br />
                                         bullets[num].x = x-22;<br />
                                         bullets[num].y = y;<br />
                                         bullets[num].xspd = -BULLETSPEED;<br />
                                         bullets[num].yspd = 0;<br />
                                         }<br />
                                         }<br />
}<br />
<br />
// forward function increase the tank's speed<br />
void forward(int num)<br />
{<br />
     tanks[num].speed++;<br />
     if (tanks[num].speed &gt; MAXSPEED)<br />
     tanks[num].speed = MAXSPEED;<br />
}<br />
<br />
//reverse function decrease the tank's speed.<br />
void reverse(int num)<br />
{<br />
     tanks[num].speed--;<br />
     if (tanks[num].speed &lt; -MAXSPEED)<br />
     tanks[num].speed = -MAXSPEED;<br />
}<br />
<br />
// turnleft function rotate the tank counter-clockwise<br />
void turnleft(int num)<br />
{<br />
     tanks[num].dir--;<br />
     if (tanks[num].dir &lt; 0)<br />
     tanks[num].dir = 3;<br />
}<br />
<br />
// turnright function rotate the tank clockwise.<br />
void turnright(int num)<br />
{<br />
     tanks[num].dir++;<br />
     if (tanks[num].dir &gt; 3)<br />
     tanks[num].dir = 0;<br />
}<br />
<br />
//getinput function check for player input keys (2 player support)<br />
void getinput()<br />
{<br />
     // hit esc to quit.<br />
     if (key[KEY_ESC])<br />
     gameover = 1;<br />
     <br />
     // WASD / SPACE keys control tank 1<br />
     if (key[KEY_W])<br />
     forward(0);<br />
     if (key[KEY_D])<br />
     turnright(0);<br />
     if (key[KEY_A])<br />
     turnleft(0);<br />
     if (key[KEY_S])<br />
     backward(0);<br />
     if (key[KEY_SPACE])<br />
     fireweapon(0);<br />
     <br />
     // arrow / ENTER keys control tank 2<br />
     if (key[KEY_UP])<br />
     forward(1);<br />
     if (key[KEY_RIGHT])<br />
     turnright(1);<br />
     if (key[KEY_LEFT])<br />
     turnleft(1);<br />
     if (key[KEY_DOWN])<br />
     backward(1);<br />
     if (key[KEY_ENTER])<br />
     fireweapon(1);<br />
     <br />
     // short delay after keypress<br />
     rest(10);<br />
}<br />
<br />
// score function add a point to the specified player's score<br />
void score(int player)<br />
{<br />
     // update score<br />
     int points = ++tanks[player].score;<br />
     <br />
     // display score<br />
     textprintf_ex(screen, font, SCREEN_W-70*(player+1), 1, BURST, -1, &quot;P%d&quot;, player+1, points);<br />
}<br />
<br />
// setuptanks function set up the starting condition of each tank<br />
void setuptanks()<br />
{<br />
     // player 1<br />
     tanks[0].x = 30;<br />
     tanks[0].y = 40;<br />
     tanks[0].dir = 1;<br />
     tanks[0].speed = 0;<br />
     tanks[0].color = 9;<br />
     tanks[0].score = 0;<br />
     <br />
     // player 2<br />
     tanks[1].x = SCREEN_W-30;<br />
     tanks[1].y = SCREEN_H-30;<br />
     tanks[1].dir = 3;<br />
     tanks[1].speed = 0;<br />
     tanks[1].color = 12;<br />
     tanks[1].score = 0;<br />
}<br />
<br />
// setupdebris function set up the debris on the battlefield<br />
void setupdebris()<br />
{<br />
     int n, x, y, size, color;<br />
     <br />
     // fill the battlefield with random debris<br />
     for (n=0; n&lt;BLOCKS; n++)<br />
     {<br />
         x = BLOCKSIZE + rand() % (SCREEN_W-BLOCKSIZE*2);<br />
         y = BLOCKSIZE + rand() % (SCREEN_H-BLOCKSIZE*2);<br />
         size = (10 + rand() % BLOCKSIZE)/2;<br />
         color = makecol(rans()%255, rand()%255, rand()%255);<br />
         rectfill(screen, x-size, y-size, x+size, y+size, color);<br />
         }<br />
}<br />
<br />
// setupscreen function set up the graphics mode and game screen<br />
void setupscreen()<br />
{<br />
     // set video mode<br />
     int ret = set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);<br />
     if (ret != 0)<br />
     {<br />
             allegro_message(allegro_error);<br />
             return;<br />
             }<br />
     // print title<br />
     testprintf_ex(screen, font, 1, 1, BURST, 0, &quot;Tank War - %dx%d&quot;, SCREEN_W, SCREEN_H);<br />
     <br />
     // draw screen border<br />
     rect(screen, 0, 12, SCREEN_W -1, SCREEN_H-1, TAN);<br />
     rect(screen, 1, 13, SCREEN_W-2, SCREEN_H-2, TAN);<br />
}<br />
<br />
//main function start point of the program<br />
int main(void)<br />
{<br />
    // initialize everything<br />
    allegro_init();<br />
    install_keyboard();<br />
    install_timer();<br />
    srand(time(NULL));<br />
    setupscreen();<br />
    setupdebris();<br />
    setuptanks();<br />
    <br />
    // game loop<br />
    while (!gameover)<br />
    {<br />
          // erase the tanks<br />
          erasetank(0);<br />
          erasetank(1);<br />
          <br />
          // check for collisions<br />
          clearpath(0);<br />
          clearpath(1);<br />
          <br />
          // move the tanks<br />
          movetank(0);<br />
          movetank(1);<br />
          <br />
          //draw the tanks<br />
          drawtank(0);<br />
          drawtank(1);<br />
          <br />
          //update the bullets<br />
          updatebullet(0);<br />
          updatebullet(1);<br />
          <br />
          //check for keypresses<br />
          if (keypressed())<br />
          getinput();<br />
          <br />
          // slow the game down, adjust as necessary<br />
          rest(30);<br />
          }<br />
<br />
// end program<br />
allegro_exit();<br />
return 0;<br />
}<br />
END_OF_MAIN();<br />
[/code] <br />
<br />
<br />
Header (seawar.h):<br />
[code]<br />
/* SeaWar.h This file contains basic information for the game SeaWar. Written by Bob Keane<br />
*/<br />
<br />
#ifndef _SEAWAR_H<br />
#define _SEAWAR_H<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &quot;allegro.h&quot;<br />
<br />
// define some game constants<br />
#define MODE GFX_AUTODETECT_WINDOWED<br />
#define WIDTH 640<br />
#define HEIGHT 480<br />
#define BLOCKS 5<br />
#define BLOCKSIZE 100<br />
#define MAXSPEED 2<br />
#define BULLETSPEED 10<br />
#define TAN makecol(255,242,169)<br />
#define CAMO makecol (64,142,66)<br />
#define BURST makecol(255,189,73)<br />
<br />
// Define the tank structure<br />
struct tagTank<br />
{<br />
       int x,y;<br />
       int dir, speed;<br />
       int color;<br />
       int score;<br />
} tanks[2];<br />
<br />
// define the bullet structure<br />
struct tagBullet<br />
{<br />
       int x,y;<br />
       int alive;<br />
       int xspd,yspd;<br />
} bullets[2];<br />
<br />
int gameover = 0;<br />
<br />
// function prototypes<br />
void drawtank(int num);<br />
void erasetank(int num);<br />
void movetank(int num);<br />
void explode(int num, int x, int y);<br />
void updatebullet(int num);<br />
int checkpath(int x1, int y1, int x2, int y2, int x3, int y3);<br />
void clearpath(int num);<br />
void fireweapon(int num);<br />
void forward(int num);<br />
void backward(int num);<br />
void turnleft(int num);<br />
void turnright(int num);<br />
void getinput();<br />
void setuptanks();<br />
void score(int);<br />
void print(const char *s, int c);<br />
void setupdebris();<br />
void setupscreen();<br />
<br />
#endif<br />
<br />
[/code]<br />
<br />
Errors (compile log):<br />
<br />
Compiler: Default compiler<br />
Building Makefile: &quot;C:\Dev-Cpp\SeaWar\Makefile.win&quot;<br />
Executing  make...<br />
make.exe -f &quot;C:\Dev-Cpp\SeaWar\Makefile.win&quot; all<br />
gcc.exe main.o seawar_private.res -o &quot;seawar.exe&quot; -L&quot;C:/Dev-Cpp/lib&quot; -mwindows -lalleg_s -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound <br />
<br />
main.o(.text+0x12bf):main.c: undefined reference to `backward'<br />
main.o(.text+0x1332):main.c: undefined reference to `backward'<br />
main.o(.text+0x1654):main.c: undefined reference to `rans'<br />
main.o(.text+0x17cb):main.c: undefined reference to `testprintf_ex'<br />
collect2: ld returned 1 exit status<br />
<br />
make.exe: *** [seawar.exe] Error 1<br />
<br />
Execution terminated<br />
<br />
<br />
[edit] Sorry about that.]]>
		</description>
		<author>no-reply@allegro.cc (Bob Keane)</author>
		<pubDate>Mon, 14 Aug 2006 23:27:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Please put that in [code][/code] tags.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spunit262)</author>
		<pubDate>Mon, 14 Aug 2006 23:57:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Solution:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
main.o(.text+0x1654):main.c: undefined reference to `rans&#39;
</p></div></div><p>
Misspelling of rand.<br />Referenced in: <tt>color = makecol(rans()%255, rand()%255, rand()%255);</tt></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
main.o(.text+0x17cb):main.c: undefined reference to `testprintf_ex&#39;
</p></div></div><p>
Misspelling of textprintf_ex.<br />Referenced in: <tt>testprintf_ex(screen, font, 1, 1, BURST, 0, &quot;Tank War - %dx%d&quot;, SCREEN_W, SCREEN_H);</tt></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
main.o(.text+0x12bf):main.c: undefined reference to `backward&#39;
</p></div></div><p>
Just plain doesn&#39;t exist. The &quot;reverse()&quot; function is probably what&#39;s intended.<br />Referenced in: </p><pre> if (key[KEY_S])
     backward(0);</pre><p>and</p><pre>if (key[KEY_DOWN])
     backward(1);</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 15 Aug 2006 00:14:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just what I said, just less detailed because I didn&#39;t have the source. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Tue, 15 Aug 2006 00:20:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Looks like I need a new pair of glasses. Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob Keane)</author>
		<pubDate>Tue, 15 Aug 2006 05:29:09 +0000</pubDate>
	</item>
</rss>
