473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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
  1. #define ALLEGRO_STATICLINK
  2.  
  3. #include <stdlib.h>
  4. #include <allegro.h>
  5.  
  6.  
  7. //extern char allegro_id[];
  8. char allegro_id[] = "test string";
  9.  
  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();
  17.  
  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 4024
weaknessforcats
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
  1. #define ALLEGRO_STATICLINK
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <allegro.h>
  6.  
  7. char allegro_id[] = "test string";
  8.  
  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();
  16.  
  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
weaknessforcats
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

1
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. I am using Allegro to make my program work, but I...
1
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 configured allegro under mingw32 and installed Dev-c++. I...
8
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. Both the executable and the DLL are linked with...
0
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 a weird C/C++ runtime library linking issue when...
6
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 code) in Visual Studio 2005 and the /MDd C Runtime...
1
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, but until now i'm unable even to compile my simple...
2
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 known how do it in c++ (builder). In delphi I...
1
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 to the right directories but then when i compile...
18
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 using classes how can we 'hide' the fact that it is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.