Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Allegro Error (Lnk1104)

allegro error LNK1104 Visual C++

  • Please log in to reply
14 replies to this topic

#1 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 04:29 AM

Hey again guys, I'm back after a ~6month break from programming and stuff like that. Blame video games... anyway, I decided that I knew enough of C++ to move on to more complex things and learn an external library. I decided on allegro as it'd allow me to do what I need to do, simply. But after I had written my "Hello world", as such, in Allegro I ran into a problem: the LNK1104 error.

Here's the error:

[color=#000000][font=verdana, geneva, lucida,]Error	1	error LNK1104: cannot open file 'c:\users\robbie\documents\visual studio 2010\Projects\Allegro Project\Debug\Allegro Project.exe'	c:\Users\Robbie\documents\visual studio 2010\Projects\Allegro Project\Allegro Project\LINK	Allegro Project[/font][/color]


Here is the code I am using:

[color=#000000][font=verdana, geneva, lucida,]#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
	ALLEGRO_DISPLAY *display = NULL;

	display = al_create_display(640, 480);
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_flip_display();
	al_rest(10.0);
}[/font][/color]


Thanks
  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 April 2012 - 04:47 AM

You are getting link error because you have not properly added libraries in your projects to link to. Follow the steps to add necessary libraries to your project.

  • Right click on project -- > Properties --> Configuration Properties --> Linker --> Input
  • Select the 'Additional Dependencies" property node and then Click the on the 3 dotted (...) button
  • Then on the 'Additional Dependencies" popup, input all the libraries you want to link to on the top textbox and click on 'Ok' button
  • Click on 'Apply' button and re-compile your application.

  • 0

#3 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 05:14 AM

You are getting link error because you have not properly added libraries in your projects to link to. Follow the steps to add necessary libraries to your project.

  • Right click on project -- > Properties --> Configuration Properties --> Linker --> Input
  • Select the 'Additional Dependencies" property node and then Click the on the 3 dotted (...) button
  • Then on the 'Additional Dependencies" popup, input all the libraries you want to link to on the top textbox and click on 'Ok' button
  • Click on 'Apply' button and re-compile your application.


I've already done that, that's why I came here.

allegroerror1.png

Thanks very much for trying to help though.
  • 0

#4 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 April 2012 - 05:18 AM

  • Right click on the project in which you want to use/set library
  • Click on Properties from context-menu
  • In the window, select 'Configuration Properties' --> 'Linker'
  • In the 'General' page, set the value for 'Addition Library Directories' to the path where the library/dll resides.
  • Then go the 'Input' page. Set the 'Additional Dependencies' value to the libraries/DLLs you want to use, separated by space (or one per line in the library input popup).
  • Now rebuild

You also need to set the directory where the libraries are. Have you followed step 4 from the above steps?
  • 0

#5 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 05:23 AM

Additional Library directories has already been set to C:\allegro\lib and the additional dependency already has allegro-5.0.6-monolith-md-debug.lib in it.
  • 0

#6 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 April 2012 - 05:32 AM

Is there any possibility that your application is already running in background? Can you check from TaskManager? That's why while you are compiling, the VS is not able to edit the exe 'c:\users\robbie\documents\visual studio 2010\Projects\Allegro Project\Debug\Allegro Project.exe'?
  • 0

#7 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 08:52 AM

Well, I managed to get it to compile. But now, I have an unhandled exception at line 14.



display = al_create_display(640, 480);

Error code:

Unhandled exception at 0x0f90237b in Allegro Project.exe: 0xC0000005: Access violation reading location 0x00000000.

  • 0

#8 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 April 2012 - 09:04 AM

Well, I think you should tell us how you managed to fix the compile/link error. It'll come in help for others.

About the exception, it is because, Inside method 'al_create_display', a pointer is using which is null. So you should properly call the methods that initialize the system and resources used by the method 'al_create_display' before calling it.
  • 0

#9 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 09:16 AM

I'd love to help people, but all I did was restart my PC and it worked. So try that.

Yeah you're right about the exception, I didn't call al_init() so allegro wasn't being initialised
  • 0

#10 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 28 April 2012 - 12:12 PM

I seem to be having another error. I've made the code more complex to load an image. Here it is:


#include <stdio.h>
#include <allegro.h>
#include <allegro_image.h>
#include <allegro_native_dialog.h>

int main(int argc, char *argv)
{
	  if(!al_init())
      {
            fprintf(stderr, "failed to initialize allegro!\n");
            return -1;
      }

      ALLEGRO_DISPLAY *display = NULL;
      ALLEGRO_BITMAP *image = NULL;

      if (!al_init_image_addon())
      {
            al_show_native_message_box(display, "Error", "Error", "Failed to initialise al_init_image_addon()", NULL, ALLEGRO_MESSAGEBOX_ERROR);
            return -1;
      }

      display = al_create_display(640, 480);

      if (!display)
     {
           al_show_native_message_box(display, "Error", "Error", "Failed to initialize display", NULL, ALLEGRO_MESSAGEBOX_ERROR);
           return -1;
     }

       image = al_load_bitmap("hello.png");
       al_draw_bitmap(image, 200, 200, 0);

      if (!image)
      {
           al_show_native_message_box(display, "Error", "Error", "Failed to load image", NULL, ALLEGRO_MESSAGEBOX_ERROR);
           return -1;
      }

      al_flip_display();
      al_rest(10.0);

      al_destroy_display(display);
      al_destroy_bitmap(image);
}


Here's the error that it gives: Capture.PNG

I've stepped through the program using breakpoints and pinpointed the problem to the al_draw_bitmap(); method

al_draw_bitmap(image, 200, 200, 0);

I'm sure I'm passing the correct parameters but it still wont let me run the program past that line.
  • 0

#11 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 April 2012 - 07:29 PM

First mind that, I'm not expert with Allegro. Actually I never used it. So I'm answering you from just my programming experience.

I guess you have not passed correct 'image' parameter. The bitmap you created with a relative path. Please try with absolute path like ("C:\\hello.png"); Though ALLEGRO_BITMAP object is created with passing relative path, but the 'image' variable contains invalid data. I guess there are methods in ALLEGRO_BITMAP type like isValid, isNull, or something like that which determines whether image object is valid or not. Before calling 'al_draw_bitmap', try to check the image object with such properties.

Also I think you should check the 'image' after calling al_load_bitmap like following...

image = al_load_bitmap("hello.png");
if (!image){
al_show_native_message_box(display, "Error", "Error", "Failed to load image", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_draw_bitmap(image, 200, 200, 0);

  • 0

#12 robbiewoods05

robbiewoods05

    CC Regular

  • Member
  • PipPipPip
  • 40 posts
  • Learning:C++, C#, Haskell

Posted 29 April 2012 - 05:00 AM

I tried your suggestions and found out that the bitmap was not being loaded. I tried all of the different paths (relative and absolute) and still didn't have any luck.
  • 0





Also tagged with one or more of these keywords: allegro, error, LNK1104, Visual C++

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download