Allegro 5 Visual studio 2017 linker errors occuring - visual-studio-2017

I've got some problems getting up Allegro 5 library in Visual Studio 2017. In most cases i'm getting linker errors (unknown/unrecognized external types).
I said in most cases, because this code:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv) {
ALLEGRO_DISPLAY *display = NULL;
if (!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
source:https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Displays
compiles as usual without errors and runs as expected.
But this code:
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "allegro5/allegro_primitives.h"
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_DISPLAY_MODE disp_data;
al_init(); // I'm not checking the return value for simplicity.
al_init_image_addon();
al_init_primitives_addon();
al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
display = al_create_display(disp_data.width, disp_data.height);
al_rest(3);
al_destroy_display(display);
return 0;
}
source: the same, next tutorial.
gets me 3 errors in linker. Many other codes do as well with various numbers of errors in linker.
In this prticular case are the errors as folows:
Error code Description
LNK2019 Unrecognized external symbol __imp__al_init_image_addon reffered in function _main
LNK2019 Unrecognized external symbol __imp__al_init_primitives_addon reffered in function _main
LNK1120 Number of unrecognized external types:2
I've read that Allegro has some dependencies in freetype, so i installed it using NuGet(project pakage manager), the same way as Allegro.
I'm new to Visual Studio, so if you have a possible solution, please explain step by step (and, if you are capable of it, please explain, so I can learn something new)
If you need something to find the solution, just ask and explain how can i get it.
Thanks a lot in advance.

Yep, I'm just stupid.
I'm sorry for all the trouble I've caused.
It was because I didn't know that I have to enable the modules in project properties under Allegro 5 tab. Now I've got it up and running.
I'm very sorry for bothering you.

Glad you solved it. For the record, the addon libraries are not linked by default in the Nuget Package for VS. After installing the Allegro 5 Nuget package for your solution, right click on the project properties and select Allegro5 from the menu on the left. Go to addon libraries, and enable the addons you're using. Easy peasy.

Related

Unresolved External _main in a console application

I have the following main function:
int main(int argv, char** argc) {
MainGame mainGame;
mainGame.run();
system("pause");
return 0;
}
it throw a LNK2019 unresolved _main at me.
now i did a bit of google-ing and found countless examples of people having accidentlyt setup win32 applications instead of the intended console app, so I checked mine in linker->system->subsystem and it read console.
Had a similar problem when using SDL. I've added #undef main after #include "SDL.h" since main was defined inside SDL for some other purpose (as DimChtz pointed out in the comments). It solved the problem.
By the way, this does not have to be SDL-specific. Some other included header or source file in your project could also be #define-ing "main", which would trigger this behavior.

linking vs 2012 c++ GDAL

I created a standard windows application with VS 2012 Pro. Just a main.cpp that looks like this:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char* argv[])
{
GDALAllRegister();
return 0;
}
I have set my include path properly. I have gdal_i.lib in my Linker -> Input -> Additional Dependencies.
Link fails with the following message:
1>main.obj : error LNK2019: unresolved external symbol
_GDALAllRegister#0 referenced in function _main
(A scad of other symbols are missing as well, but this one should be easy.)
I used dumpbin and GDALAllRegister appears in the exported symbols. It does appear as "GDALAllRegister", not as "_GDALAllRegister#0".
I tried downloading and using the dev build, and also built myself. Same results.
I just know this is something simple, but I'm totally brain-cramping here. What have I done wrong?
Thanks.
-reilly.
I said it was simple and stupid, and it was.
I had the build manager set to build 32 bit.
Another 4 hours of my life I'll never get back.
Thanks to Manuell for his suggestion. It got me looking in a different direction and I found it.
Sorry, community. This is what comes from programming tired.
-reilly.
This kind of error is typical of a "Calling Convention" mismatch between EXE and LIB.
Check you have __cdecl (/Gd) in "Configuration Properties" -> C++ -> Advanced -> "Calling Convention"

Compiling Glew and SDL in C++ with Code::Blocks

I've spent the last 24 work hours trying to get this to compile, using multiple searches and tutorials (Some say I need to link it dynamically while others say I need to statically), I can not get this to work. I'm relatively new to compiling and linking so any help would be appreciated.
Here is my code(As you can tell by my comments I was very tired last night with coding this):
#define NO_SDL_GLEXT
#define GLEW_STATIC
#include "GL/glew.h"
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
int main (int argc, char* args[]){
//Loads the SDL video module
SDL_Init(SDL_INIT_VIDEO);
//Creates the SDL Surface for OpenGL to draw to
SDL_Surface* surface = SDL_SetVideoMode(800,600,32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL );
//Sets the caption...
SDL_WM_SetCaption("OpenGL",0);
glewExperimental = GL_TRUE;
glewInit();
//Main event loop, this is the BREAD AND BUTTER LADIES AND GENTLEMEN
SDL_Event windowEvent;
while (true){
if (SDL_PollEvent(&windowEvent)){
//If you close the appplication, causes it to actually stop running :D
if (windowEvent.type == SDL_QUIT) break;
//Close it with the ESC key! :D:D:D:D:D:D:D:D:D:
if (windowEvent.type == SDL_KEYUP && windowEvent.key.keysym.sym == SDLK_ESCAPE) break;
}
//Literally the one extra line of code needed to do double buffering
SDL_GL_SwapBuffers();
}
//I wish I knew what this ended...LOPE JK
SDL_Quit();
return 0;
}
And in the search directories I have:
Compiler:
E:\Programs\CodeBlocks\glew-1.10.0\include
E:\Programs\CodeBlocks\SDL-1.2.15\include
Linker:
E:\Programs\CodeBlocks\glew-1.10.0\lib\Release\x64
E:\Programs\CodeBlocks\SDL-1.2.15\lib
And finally in the Linker settings I have
Link libraries:
E:\Programs\CodeBlocks\glew-1.10.0\lib\Release\x64\glew32s.lib
Other linker options:
-lmingw32 -lglew32s -DGLEW_STATIC -lSDLmain -lSDL
The error I am currently getting is:
In function 'SDL_main':
undefined reference to `glewExperimental'
undefined reference to `glewInit#0'
Thank you in advance for all the help!
You are getting linker errors. It looks like you are compiling your application using the Mingw compiler. But, are you sure the glew library you are using was also built with/for Mingw? If you didn't build glew yourself and downloaded a prebuilt binary, it was most probably built using Visual Studio. Note that its not straightforward to mix libraries from different compilers like this.
Look at this:
http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
P.S: Unless philosophical reasons against proprietary software is preventing you from doing so, you really ought to consider using Visual Studio compilers. The express editions of Visual Studio compilers are free (beer-like). You can use the Visual Studio compiler in really great IDEs like QtCreator.

The procedure entry point _gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll Error

Yesterday I decided to download, install, and attempt to use Allegro 5. I also downloaded Code::Blocks 12.11 w/ the MinGW compiler. I set up everything and installed everything correctly (or so I thought) and tried to run a sample code to see if it would work:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
When I attempt to compile and run the program an error message box appears saying "The procedure entry point _gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll." I searched the web for about an hour trying to find a fix for this problem, like I do for most things, but I came up empty handed. I'm wondering if anyone has any ideas for any fixes to this problem, if so, let me know ASAP! Thanks in advance!
__gxx_personality_v0 is used in the exception handling of the C++ library. MinGW can support a couple different exception models on the x86: sjlj (setjmp/longjmp) or DWARF (DW2). As far as I know, which model will be used is compiled into the compiler - it's not something that can be selected with a command line option.
The sjlj exception model will link to __gxx_personality_sj0, the DW2 exception model links to __gxx_personality_v0. It seems like your compiler is building for the dw2 exception model, but at runtime it's finding a libstdc++-6.dll that was built with the sjlj model. See if you have multiple versions of libstdc++-6.dll on youR system, and see if copying another one to the same directory as your program fixes the problem.
You can use nm libstdc++-6.dll | grep personality to see which exception 'personality' the DLL is using.
I ran into this as well. Did some searching, someone mentioned paying attention to whether or not you were in Debug or Release Mode. This applies to Code::Blocks specifically. I found I was in Debug Mode. I changed that to Release Mode and my program compiled and ran.
I am troubled by this though... It seems to me it should work in both modes, so how do I fix it so that it will? I have no answer there. Maybe someone will comment with the solution. In the meantime, compile and run in Release Mode instead of Debug Mode.
I just did a little mad science, removed the libstdc++6.dll from MinGW/bin and put it in another folder. Then I copied over the same file from Gimp/bin. No more linker error, instead I get an error that says the application failed to start :( Still compiles and runs in Release Mode though.

GTK having issue with Visual Studio

I am new in C++ stuff and visual studio. Somehow I managed to add GTK lib and includes in Additional Include Directory! here is how i added
C:\gtk\include\atk-1.0;C:\gtk\include;C:\gtk\include\gdk-pixbuf-2.0;C:\gtk\include\pango-1.0;C:\gtk\include\cairo;C:\gtk\lib\gtk-2.0\include;C:\gtk\lib\glib-2.0\include;C:\gtk\include\glib-2.0;C:\gtk\include\gtk-2.0;%(AdditionalIncludeDirectories)
all files set correctly and no error with linking.
But when I compiling code I got this errors!
here is image!
This is unrecognized error for me any one know what's the matter!
here is code (this is basic code i get from tutorial over internet)
#include<gtk\gtk.h>
int main(int argc,char* argv[]){
gtk_init(&argc,&argv);
GtkWidget* window;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
gtk_widget_show(window);
gtk_main();
return 0;
}
thanks for help! and your time