472,337 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

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 3859
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

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

Similar topics

by: me | last post by:
I have been looking online for a year, and cant find one. I used to use the int86() command in dos command-line mode, but it can't work in linux....
by: Karol | last post by:
I wonted to write programs with allegro library under Windows so I have downloaded Dev-c++, allegro library, mingw32 and dx70 for mingw. I...
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code....
by: Philip Lowman | last post by:
I am in the process of trying to migrate a couple of build solutions to Visual Studio Express 2005 from VS 2003 Professional and I am running into...
by: John | last post by:
I have 5 native static libraries that are being compiled in Visual Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all managed...
by: HugoScripts | last post by:
hi there, as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro,...
by: amarok | last post by:
I've got a problem - I must to static link to dll library, which is placed in subdirectory of application. I knonw how do it in delphi but I don't...
by: drsmooth | last post by:
i am trying to get the allegro graphics library to work on my computer, im using visual c++ 6, i downloaded the binary version and copied the files...
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.