How to make your own SDK from code files? - c++

I have programmed a game with lots of C++ code and it started to take more time then ever to compile my code.
So I thought maybe I can split the game's rendering code as it's own binary SDK.
I have used many SDKs and APIs before, But I don't know how to make my own SDK and how does it all hold up together.
Does any one know a good online tutorial or book about how to make a SDK. thanks.

You need to read about creating libraries. You then compile your game's rendering code as it's own library file.
Here is an example of how do create and use a static library using Visual C++ : http://msdn.microsoft.com/en-us/library/ms235627.aspx
PS: As for increasing compilation times, consider using pre-compiled headers on your platform.

Related

How to create a portable executable with allegro 4.4.2

So I am creating a C++ program using the allegro version 4.4.2 library and I need to be able to produce an executable package which I can submit to a course instructor and have run on his computer without issues. I am developing the program using DevC++. If I am understanding this correctly so far, I need to link to a static library for allegro and then the executable should include the library info and thus the library itself is not necessary to have included in the executable package. I have also seen some recommendations regarding third party tools that produce executable packages, but these seem to be more general (not necessarily allegro compatible?) and I am hoping to avoid downloading more third party software.
I have tried linking to the static library liballegro-4.4.2-monolith-static-mt.a but for some reason when I do this I get a whole slew of undefined reference compile time errors. I have read that it is necessary to have #define ALLEGRO_STATICLINK included in the project, I have this statement at the top of my main source file but I am not sure if I am meant to define this somewhere in the project options instead?
Any guidance or link to resources which will help me solve my problem would be extremely appreciated! I am just getting into the meat of programming with C++ beginning to learn object oriented programming methods, I still occasionally struggle with the basics so thank you in advance for your help!
Backstory (if interested/relevant?): I am taking a Game AI programming course for which we need to create some example programs to demonstrate AI algorithms. The course specifies Java but I am most familiar with C++ and the course instructor says this is fine but I must be able to submit an executable to him which he can just run on his computer without issues. To best achieve what the course asks I feel the allegro library (which I already have installed) will be of great help, mostly for drawing graphics to the screen and such.
So I just ended up using a dynamically linked version of my program and including the appropriate .dll files which turned out to be a lot less work than I thought it would be.
Basically I just had to ensure the allegro-4.4.2-md.dll from the bin folder was included in the folder with the executable. I then sent off the package (the .exe compiled file and the needed supporting files such as bitmaps sound files etc) to a few friends and had them try to run it. They then gave me the warnings from their computers along the lines of "Test.exe cannot be run ****.dll cannot be found".
I searched the exact names of the dll files they were receiving warnings for in the folder with my game and voila it now seems to execute on whatever PC it is sent to.

Link c++ object during runtime?

I'm trying to write my first game in c++, and I want it to dynamically load everything from files. This includes the enemies, and I was wondering if there was a way to dynamically include their code at runtime, instead of linking the on compile, so that the levels are easily interchangeable. Lua might be an option but I have no clue where to start, and dll seems to be Windows-only (and I wouldn't know where to start there anyway). Can anyone help with this?
tl;dr I want to link in code to my c++ game at runtime.
For the Lua approach you first need to choose the version first. Right now there is the major version 5.1 and 5.2. My previous work was using 5.1 and for my new project I decided to update to 5.2, however I found that my favorite script wrapping tool (SWIG) does not work with 5.2. Just something to decide at the beginning, because you do not want to get a version working and then have to change it.
Lua comes with makefile build environment. My first experience of trying to build on Windows was a bit of a nightmare, did not appear to just run out-of-the-box, so I opted to create my own Visual Studio project at the time, and just include all the .C files in the project. There are two files which need to selectively included/excluded depending on how you intend to compile: lua.c and luac.c. If you are planning to embed Lua in your app, then exclude both of these files; they both contain a main() function and are designed to build console apps. Include all the rest of the C files in your project.
You should be able to compile easy from this point.
When you include the headers of Lua, keep in mind that the functions are C functions so if you are including them from C++ you need to wrap the file inclusion inside of: extern "C" {} - example: C++ Lua 5.1 Issue
Wrapping your interfaces in another topic and there are lots of resources available. My favorite is SWIG but there are lots of options, including hand coding the conversion of your C/C++ -> LUA -> C/C++ code. Would recommend just focusing on getting the first part working first, get the interpreter embedded so that you can run a "hello, world!" script from Lua inside your app.
So going by your requirement of crossplatform use and dynamic linking, what you're probably looking for is an environment like QT which has QLibrary: https://stackoverflow.com/a/9675063/453673
But https://softwareengineering.stackexchange.com/questions/88685/why-arent-more-desktop-apps-written-with-qt
MingW is the open-source equivalent for Visual C++, so it can help you writing code for Windows (though if I had a choice, I'd directly use Visual C++). The way dll's are loaded in Windows is somewhat similar to the way they're loaded in Linux, so you'll be able to write code with #ifdef's to do conditional compilation. I've written one such program a couple of years back.
To load a shared library(always with .so as suffix) under Linux, you could use dlopen(), dlsym() and dlclose()

How to build a koolplot library using VC++ 2010

I want to use simple plotting functions in my C++ code. Presently I am using Qt5 with VS2010 c++ compiler. I came across this library called koolplot. But I cannot buid it with VS2010 from its source files. I am opening vs2010 cmd and running nmake...It shows winbgim.h missing..I copied that header in MinGW include folder and ran it ...now it shows "Plotdata.h:warning: 'typedef' was ignored in this declaration" Please help...if any one knows a simple plotting library running with VS2010 please suggest..
According to its website, Koolplot is designed for the MinGW/gcc toolchain - you'll have to do a bit of leg work to get it to compile on Visual Studio, though I don't know specifically what you'd have to do without taking a closer look.
Also, the library seems to do its own window management and the like, so I'm not sure how well you'll be able to integrate it with Qt.
koolplot needs WinBGI library (BGI = Borland Graphics Interface?).
I have changed it to use native Win32 using VS2008:
http://www.tu-chemnitz.de/~heha/hs/koolplot-heha.zip/
It's still incomplete as a good Win32 implementation would implement koolplot in a DLL which self-registers a Window class, and has both C and C++ interface. Moreover, koolplot as-is doesn't support multiple scales, finer plotting options, GDIplus, and fast data update, so it's not the right thing to write an oscilloscope program.
It's C++ code is also outdated as there are lambda functions available now.
However, good integrating into Qt is another task.

trying to set SDL up on Code Blocks

I made a tic-tac-toe game in c++ want to learn how to use SDL so I can make a graphical interface, but I having trouble getting the SDL headers to work. This is really the first library I have had to download and minitech helped me out with decompressing the .gz files, so I got that done but now I don't know how to link it to Code Blocks so that I can use the library.
Make sure to check the CodeBlocks wiki page on using SDL with it, if you haven't already. It explains how to install it and then finally how to link your project to it so you can take advantage of the libraries in your application.
It looks like CodeBlocks supports Dev-C++ "DevPaks" now which is probably an even easier way of installing it than manually copying static libraries around.

Building/Running Lua from Visual Studio

I'm a total noob when it comes to linking and building with Visual Studio. I would like to integrate Lua into my C++ console application.
Can someone give a step by step on how to do this from getting the Lua dependencies from lua.org, to actually running a "Hello World from Lua" in VS, and all the steps in between.
Finding something like this online has been very difficult since most require prerequisite knowledge of building Lua and such.
Thanks :)
Start with the Lua for Windows package. It will get you a self-contained batteries included Lua installation. Lua for Windows is not an official distribution, but it is well respected by the Lua user community. You can use its lua.exe to gain experience with the language in a Windows environment, and its rich collection of tested extension modules is also available for use.
If you add its include and lib folders to your VS project configuration, you should be able to compile and link against Lua in short order.
One possible complication is that the LfW distribution is built against VC8's C runtime library. If that becomes a problem, then you can either compile Lua yourself as part of your Solution, or get a known good DLL that matches your specific version of Visual Studio from the Lua Binaries project.
Do remember that if you are using one of the distributed DLLs, it will have been compiled as C, and not C++. That means that you must wrap any references to the Lua include files in extern "C" {...} or you will have problems with linkage.
It really helps to have some experience with VS project configuration and building. In particular, experience with mixing C and C++ in a VS project is very helpful.
I heartily recommend following the advice already given about learning C and C++ and mixing the two together. Once you have that under your belt, you may want to check out LuaBind or LuaPlus for connecting C++ and Lua. You can do it manually (and you probably should, at first, to understand what's going on under the hood), but it's more efficient and cleaner, code-wise, to use one of those binding libraries. For debugging purposes, Decoda is a good choice; it can attach to processes started in VS which contain Lua code you want to check.