470,604 Members | 2,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

Need help with static linking Allegro with C++ and making it work...

I'm starting to learn how to use the Allegro library with C++ on my own. My compiler is MSVisual C++ 6.0. The book I am learning out of is "Game Programming All In One, Third Edition" by Jonathan S. Harbour. I've been able to get all of the programs so far to run correctly except for the first one after setting up the compiler to statically link. I've installed the SDK for Direct X properly and the compiler has no problems linking. Yet, I can't get the first "GetInfo" program on pages 81-82 to work!

I use an empty Win32 app and saved the main program as main.c. I open up the Project Settings (I didn't see Project Properties)/Link and replace everything in the "Object/Library Modules" text box with the following: alleg.lib alleg_s.lib gdi32.lib winmm.lib ole32.lib dxguid.lib dinput.lib ddraw.lib dsound.lib

My Code exactly as I have it copied:
Expand|Select|Wrap|Line Numbers
  3. #include <stdlib.h>
  4. #include <allegro.h>
  7. //extern char allegro_id[];
  8. char allegro_id[] = "test string";
  10. int main()
  11. {
  12.  allegro_init();
  13.  printf("Allegro version = %s\n", allegro_id);
  14.  printf("\nPress any key...\n");
  15.  system("pause");
  16.  allegro_exit();
  18.  return 0;
  19. }
  20. END_OF_MAIN()
NOTE - I have the "extern char allegro_id[];" as a comment because I don't know whether to include it or not.

I get one warning "warning C4013: 'printf' undefined; assuming extern returning int"

If I add the "extern char" line, it doesn't seem to make a bit of difference...

I've checked my C++ reference guide and I think I've done everything right! I've copied from the first "#include" to the "END_OF_MAIN()" exactly like it is in the book... What am I doing wrong? I've been trying to make it work for almost a month and I know it's got to be something simple that I'm missing... Help me please!

Silver Leaf
Apr 9 '08 #1
4 3720
9,208 Expert Mod 8TB
You are defining an array named allegro_id as a char array containing a string.

That means you don't need the extern extern char allegro_id[]. However, if you have another source file and you want to use the array defined in this file then inthe other file you have extern char allegro_id[] because the array is external to that other file.

printf is declared in <stdio.h>, which you have not included.
Apr 9 '08 #2
THANK YOU SO MUCH!!!! :) That cleared that problem up! It compiled with no problems. When I tried to build it before running it, I came up with 109 errors and 1 warning!

The new code is:

Expand|Select|Wrap|Line Numbers
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <allegro.h>
  7. char allegro_id[] = "test string";
  9. int main()
  10. {
  11.  allegro_init();
  12.  printf("Allegro version = %s\n");
  13.  printf("\nPress any key...\n");
  14.  system('pause");
  15.  allegro_exit();
  17.  return 0;
  18. }
  19. END_OF_MAIN()

The first bunch of errors are "alleg_s.lib(allegro.obj) : error LNK2005:" and says that many things like _get_allegro_version and _install_allegro are "already defined in alleg.lib(alleg42.dll)"

The second bunch of errors are "MSVCRT.lib(MSVCRT.dll) : error LNK2005:" and says that many things like _malloc and _free are "already defined in LIBCD.lib" with an item like dbgheap and fflush ending in ".obj" in ().

The next one is "LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:libarary"

The next bunch of errors are "alleg_s.lib(wsystem.obj) : error LNK2001: unresolved external symbol _imp_" and end in things like SetWindowTextA@8 and RedrawWindow@16.

The next ones are similar same but have things like "wddovl.obj" and "wddwin.obj" instead of "wsystem.obj"

The last two are "LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main" and "Debug/main.exe : fatal error LNK1120: 56 unresolved extrnals"

Any suggestions on this one?

Silver Leaf
Apr 10 '08 #3
9,208 Expert Mod 8TB
What kind of VC++ project are you creating?

Since you are using VC++ 6.0, you should be creating a Win32 project. Then go to your Project Settings and select a) console application and b) empty project.

If you have a file named stdafx.h generated for you, then you have the wrong project.

My next question is how you are using this allegro library. That is, how are you adding it to your project?
Apr 11 '08 #4
The program is Win32. Right now, I'm just trying to get its stats. Once I have the kinks worked out of that, then the next chapter covers 2D vector graphics programming...

Silver Leaf
Apr 14 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Robert A Riedel | last post: by
2 posts views Thread by amarok | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.