Allegro.cc - Online Community

Allegro.cc Forums » I can't use add ons on Visual Studio 2019 » Reply

 Forums: I can't use add ons on Visual Studio 2019: Reply
This section is only available to registered Allegro.cc members.
 Thread Review
BauKSA:

I am new to Allegro 5 and Visual Studio... I'm trying tu run a simple code:

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

int main(){
al_init();
al_init_image_addon();

return 0;
}

And it returns an error:

LNK2019 Unrecognized external symbol __imp__al_init_image_addon reffered in function _main

I already install Allegro5 from NuGet packages and enable add ons on project properties... but it still doesn't work...

Please if anyone has a solution, tell me, because I am breaking my head thinking it xD

If I delete the line al_init_image_addon(); it works perfectly and also U can create and destroy displays, for example... but the add ons simply doesn't work.

DanielH:

If you include the header you need to link the library

In Allegro 5, each addon is its own library.
Link the image library to your project.

Adding Allegro5 with NuGet doesn't automatically link any addon libraries. You still have to link them yourself.

If you use added Allegro with NuGet it's easy:
1. Open Project Properties
2. Select the Allegro tab
3. Pick the addons you want (Select "yes" for each)

if not then:

1. Open Project Properties
2. Linker tab
3. Add each addon library to the "additional dependencies" line

Now it should be properly linked.

BauKSA:

I have already done that. But still doesen't work... I really don't understand the problem...

DanielH:

It should have worked

An idea: Did you do it for the configuration you are using?

Sometimes I accidentally modify properties for the release configuration when I'm working on the debug configuration.

BauKSA:

mmm, how?? I have Visual Studio 2019 Community, I install Allegro 5.2.8 and checked all the add ons on the properties... only that. Do I need to do something else??

DanielH:

Somehow it's not linking. for the time being, you can add the library file name to the additional dependencies.

Try that and see if it works

I'll check when I get home, but can't think of what it could be.

[EDIT]
Everything checks out.

1. create empty project
2. manage nuget and add allegro5
3. open properties->allegro5 and select addons
4. create a main function
5. compile

Here's my code:

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

int main()
{
  al_init();
  al_init_image_addon();

  return 0;
}

No issues.

As I asked before, when you selected the addons, did you select them for all configurations?

In this image, I only set the addon for the release configuration.

{"name":"613229","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/0\/d0968f2b9b1056e6b0509fb7389a9d37.png","w":617,"h":428,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/0\/d0968f2b9b1056e6b0509fb7389a9d37"}613229
I got the same linking error because I'm not compiling in release mode.

That's the only thing I can think you're doing.

Anyone else have ideas?

Dizzy Egg:

I concur, should be working fine so long as you have the add-ons selected for the current build (debug/release). Tested this morning with VS2019, Nuget. I can't think of any reason it wouldn't work unless you're compiling for a build without having the add-ons selected for it...