[Solved] Visual Studio question

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

[Solved] Visual Studio question

Post by captjack »

I've run into a bit of a snag.

To date, I've been working on my tile engine and this has been going pretty well. I'm at the point now where I'd like to build out the map editor so I can stop fiddling bits in map files by hand. Seems straight forward and I thought I had a good game plan.

I'm trying to write the engine following OOP methods as much as possible. So far I've only strayed from that goal when I got too carried away.

I'm using Visual C++ 2008 Express. I have one solution file. In that solution I have my engine project. (I cheated and put the game code in the engine project as well.) Now that I can fire up SDL and get the map and tiles loaded, and can move my player around the screen under camera control, I've decided to work the map editor.

So, I added a project to my solution file. Since I want to use the code base from my engine to drive portions of the map editor (rather than code from scratch), I've #included the necessary headers to my map editor. I can get the bare main() to compile. But I get link errors (LNK2019 specifically). I know why... the linker can't find the obj code needed by my engine.init_engine() call and so on.

Code: Select all

#include "../sword/SwordEngine.h"
#include "../sword/Common.h"

int main(int argc, char* argv[])
{
	CSwordEngine engine(ENGINE_MAX_X, ENGINE_MAX_Y, ENGINE_BPP);

	engine.init_engine();
	engine.set_window_title("Map Editor");
	engine.start_main_loop();

	return 0;
}

Code: Select all

1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::start_main_loop(void)" (?start_main_loop@CEngine@@QAEXXZ) referenced in function _SDL_main
snip snip snip
1>C:\Visual Studio\Projects\sword\Debug\mapedit.exe : fatal error LNK1120: 5 unresolved externals
But how the hell do I tell it where to find them? I don't have that stuff in a .lib or .dll or anything like that, but those are the only "solutions" I found on my google explorations.

Any suggestions are greatly appreciated!

-captjack
Last edited by captjack on Thu Apr 29, 2010 9:32 pm, edited 1 time in total.
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Visual Studio question

Post by mv2112 »

Ugh, did you include the C++ files that define all the class functions too or did you just include the header files? Or are the functions defined in the headers?
There error looks like its saying that it cant find the function definition. You would have to copy some C++ files from your engine project to the map editor project.
If this is the problem, you could compile your engine code into a lib and link it to the map editor project.
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

Re: Visual Studio question

Post by captjack »

mv2112 wrote:Ugh, did you include the C++ files that define all the class functions too or did you just include the header files? Or are the functions defined in the headers?
There error looks like its saying that it cant find the function definition. You would have to copy some C++ files from your engine project to the map editor project.
If this is the problem, you could compile your engine code into a lib and link it to the map editor project.
Hi there!

I've got everything broken down into specification files (.h) and implemention files (.cpp). I've only #included the specification. I figured that the error was related to the linker not finding the function defs, but I was hoping :shock: that the solution file would tell the projects where to find dependent obj files. I did set the project dependencies, but now I'm guessing that this only applies to compilation and not linking.

I don't have a clue how to go about building a library. If it's anything like an .so in Linux, then I'll pound my head through the wall, get drunk, and tackle this next month... It's been a few years since I did that kind of work.

-captjack
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Visual Studio question

Post by mv2112 »

All you really have to do to make a static library is take main.cpp out and change the project type to .lib. To make it easier, add the header files and the .lib file to the VC++ Directories, that way you dont have to copy all header files to the new project and VC++ will be able to find the .lib when you link it. I just did it with the engine im working on. 8-)
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

Re: Visual Studio question

Post by captjack »

mv2112 wrote:All you really have to do to make a static library is take main.cpp out and change the project type to .lib. To make it easier, add the header files and the .lib file to the VC++ Directories, that way you dont have to copy all header files to the new project and VC++ will be able to find the .lib when you link it. I just did it with the engine im working on. 8-)
I'm going to play with the suggestion you made about creating a lib. It will be a good exercise to learn more about the internals of Studio.

But, I discovered that you can add an "Existing Item..." to a project. If you right-click the "Source Files" of your project, Add..., and "Existing Item...". Surf to the location of your other project's files and select the one you need. Rinse and repeat for all the implementation files you need. It's uglier than I was expecting since I have "dupes" of all the files lying around (well, pointers to the originals I think). The nice thing is that it appears that if I edit the Engine.cpp file in the map editor project, the "master" Engine.cpp file from the engine project is kept in sync. (There's probably something I'm not explaining right, but it works and that's good enough for now!)

I did that (and put SDL_image.lib in my linker properties :shock:) and viola!

Thanks so much for shaking the fog from my head. The simplest things are the hardest...
Post Reply