Archived

This topic is now archived and is closed to further replies.

Psycho_Bastard

Multifile program

Recommended Posts

Hi all, my first post to this site..... My name is Blair and I am in my final year of my degree. (Leisure Computing Technologies) ... means game design, but we don''t do enough for my liking.... Anyway, enough of that... I have a wee problem. Using the nice and simple tutorial 6, the one for textures. I tried to seperate the code for loading textures so that I could call it from my main file using a function like this LOADTEXTURES(); yep, you guessed it.. I wanted a seperate file to load the textures... (loadtextures.cpp) **This file will be used just for the world textures, floor, walls and buildings etc..** When I tried (several methods) to seperate the code it always screwed up and gave me a nice list of errors error C2601: ''LoadBMP'' : local function definitions are illegal They are normally all like that.... Would anyone like to see if they can get tutorial 6 in a multifile format proving to me that it can be done.... I am a fish out of water... I am a fish...... I am out of the water .... Damn

Share this post


Link to post
Share on other sites
first off, are you including this file after the other include files?

for instance:

#include <openglstuff.h>
#include <moreopenglstuff.h>
#include "loadtextures.cpp"

if you aren't doing that, do that, and then make sure that you are excluding the file from the build on the left tab (in Visual Studio)

Hope that helps!

-jverkoey

oh, i forgot to say, you also need to make any necessary prototypes that your function uses BEFORE you include it, or it won't think that any of the commands that you made in the BaseCode exists....

[edited by - jverkoey on January 30, 2003 6:10:20 PM]

Share this post


Link to post
Share on other sites
It''s always a *bad* idea to include cpp files, such as :

  
#include "loadtextures.cpp"


If your function LoadBMP is not defined, that means the compiler can''t find it.
In the file when this error happens, write something like that in the beginning of the file :

  
extern AUX_RGBImageRec *LoadBMP(char *Filename);


for instance, if your main.cpp file calls the function LoadBMP, you have to write that line in the beginning of the main.cpp file, as well as all files in your project that uses the LoadBMP function.

Share this post


Link to post
Share on other sites
Question 1... just wondered why you said it was bad practice to include files like this "filname.cpp"
It''s not in my books... just the header files like that but no explination as to why.....

Anyway, I tried putting the texture code into a function in the SAME file... I still get the errors.. is there something I don''t know about OpenGL and functions ?

Try it yourself (get lesson 6 and put the code into a function so that you can (attempt) load the textures by calling the function loadtextures(); my flatmates looked at it (competent C++ programmers) and they can''t figure it out either.... we are missing something... I know it''s gonna be sooo dammed simple to fix... just don''t know what it is ARGHHH

I am a fish...... I am out of the water .... Damn

Share this post


Link to post
Share on other sites
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcrefCompilerErrorC2601.asp

- Yuval

Share this post


Link to post
Share on other sites
You don''t have to include cpp files because it''s not meant to. Header files (*.h) declare functions. Source files (*.cpp) define them. These are two different concepts.
If you include the CPP file, you''ll be able to define the function twice, which is forbidden in C/C++. Go read C/C++ programming books if you don''t believe me. I''m sure many books already discuss the topic.

quote:

Would anyone like to see if they can get tutorial 6 in a multifile format proving to me that it can be done....

Yes I did it and the solution I proposed above works very well. Have you tried it ?

Share this post


Link to post
Share on other sites