Jump to content
  • Advertisement
Sign in to follow this  
guillermoro

Object File Libraries

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to make an engine that is completely seperate from my game that im creating using it. I want the game to link the engine in a lib file. How do i create a .lib file using microsoft visual c++ express edition. Also im having some intellisense problems with my engine, i might be doing something wrong but ive heard other people having this problem also. Any info on either of these topics would be appreciated. Thank you :-)

Share this post


Link to post
Share on other sites
Advertisement
I'm not too sure about using a .lib, but I do know a fair ammount about creating a .dll. The least I know about a .lib is how to make a project. In VC++, you need to make a .lib project. You can do this by creating a project, and selecting it to be a Win32 Static Library. For a .dll, you need to make a Win32 Dynamic Link-Library. In the DLL, you create various functions you wish to use in your project. In order for someone to access them though, you need to mark all exported functions as "C functions." This enables use of the function across multiple languages. If you've ever read the code "extern C { ... }," this is how you would do that. Next, if you're going to be using other languages than just C/C++, you should put every exported function in the '__stdcall' calling convention. Next, for any functions to be exported, you need to put the __declspec(dllexport) macro infront of it. This signals to the compiler to make the function open to calling. I find making a macro for this helps save a little bit of time.

One last tid-bit. If you're making this DLL for non Visual C++ projects, you need to include a .def file. I'm not going to go into much detail about this, as it can get complicated. Some basic information can be found here.

Some code to help you chomp this down:


//My little cheat
#define __dllexport __declspec(dllexport)

extern "C"
{
__stdcall _dllexport void MyFunc(void)
{
//Do stuff...
}
}





EDIT:

Ah! I forgot to tell you how to import functions!

In your game, you need to make a header file for all structures/functions you created in your .dll. In order to import a function, you simple have to change the declspec to dllimport. For example:


#define __dllimport __declspec(dllimport)

__dllimport void MyFunc(void);


One last tid-bit. If you're using Visual C++, you can use __dllimport/__dllexport for functions, variables, and objects. However, if you're going to import/export options, drop the __stdcall & extern "C" part of the code.

If you have anymore questions, feel free to ask!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!