Jump to content
  • Advertisement
Sign in to follow this  

Problem compiling my first script (and proabablly also with MSVC10)

This topic is 2224 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

I've been trying to teaching myself the basics of Angelscript from the Angelscript website ( http://www.angelcode.com/angelscript/ ), but the tutorials on this website seem to assume a previous knowledge of cpp (Well I tried teaching myself cpp quite a while ago, but I never got past printing things to a command prompt) and as a result, although I might know how Angelscript itself works, I have no idea how to compile it into an actual program. (I've done a lot of modding for the game Amnesia: The Dark Descent, which is built around AngelScript. As a result, I know a lot about the basic syntax of Angelscript and how to use it, but I don't really know anything about actually making my own programs with it.)

First I downloaded Microsoft Visual C 2010 Express, used it to compile the Angelscript library, and then copied the resulting library file into the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib folder. Next i took the Angelscript.h file and all of the addons (from the angelscript sdk addons folder) and copied those into the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include folder. I'm not sure if this was the right thing to do, but it seemed like it at the time.

Having done what I assume to be the required steps necessary to set up the script, I followed the instructions on the "your first script" page ( http://www.angelcode...dk...world.html )... or rather I tried to. I'm not exactly sure what all the code that is givin there for, but looking at some of the sample folders that came with the Angelscript sdk I decided it was for the main.cpp file that should be placed in a folder called "source". So I made a new folder somewhere on my computer named "test," and made a folder inside that named source, and saved the all script on that page (except for the "test.as" script and the script at the bottom labeled "helper functions") as main.cpp inside of this folder. I then (again using the other samples as reference) made a folder inside "test" named "bin," where I put the "test.as" file that the page instructs me to make.

After that was done, I opened up MSVC10 and made a new "empty project" in the "test" folder named "test_project." I then went to Project>Add Existing Item in MSVC10, and added the main.cpp file that was in the "source" folder and saved the project.

I have attached what I had so far.

I then went to Debug>Build Solution and tried to compile the project. However it gave me a bunch of errors and the compilation failed (It looked like a lot of these errors were errors about the syntax of the main.cpp file, but I don't really know). I have no idea what I've done right and what I've done wrong, or how to set it up so that it will compile properly. All I'm really trying to accomplsih right now is to figure out how to set up a project in MSVC10 that compiles correctly, so that I can begin teaching myself the basics.

I would appreciate any help,
Thanks a lot!

Share this post

Link to post
Share on other sites
Integrating AngelScript into a C++ problem is definitely not a trivial task, though I try to make it as easy as possible. C++ itself is a complex language and AngelScript takes advantage of a lot of its powerful lowlevel features to work well. If you do not understand well how C++ do memory management, pointer arithmetics, type casts, etc, then you are likely to have difficulties in integrating AngelScript in your application.

By the looks of your questions, you have a long way to go. I'll try to help as I can, but perhaps you should consider writing a few simpler C++ programs first before you try to write applications that need integrated script engines to do what you want. You need to get an understanding of C++ first to have a solid foundation before tackling the complexity of integrating a script engine.

Instead of copying the angelscript library, header, and add-on source codes into the MSVC install directory I suggest you include extra search paths in your project settings to tell MSVC to look in the folders where you have the AngelScript SDK. Look for 'Additional include directories' in the C/C++ category and add the directories with the header files. Look for 'Additional library directories' in the Linker category and add the directories with the library file. This will avoid polluting your MSVC installation and will make it easier to upgrade AngelScript as I release new versions.

All these folders that you created, i.e. 'source', 'bin', etc, are really not necessary. It is just my way of keeping things a bit more organized. As you gain more experience with C++ you may find other ways that suit you better.

Rather than examining what you've done already I suggest you start over, and start with something small. For example a simple 'hello world' program.

1. Start a new MSVC project
2. Choose console project so you don't have to worry about the Win32/64 API to begin with.
3. Add a new c++ file called main.cpp
4. Add the following code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
printf("Hello world\n");
return 0;

5. Compile the program.

Unless I missed something and you get a compiler error, you should now have an executable in the <project>/Debug/ folder (where <project> is the location of the project you created). You can run this program from the command prompt (Run cmd from start menu) and it should print 'Hello world' on the screen. If you run it from the file explorer you'll likely just see the command prompt flash and then vanish again.

Once the hello world example is working, expand on it by adding the scripting functionality. For example by looking at the 'tutorials' example.

Share this post

Link to post
Share on other sites
Ah, thanks a lot for the help! It's actually rather embarrasing because I already knew that my main.cpp file had to have a main() (or main(int argc, char **argv) I suppose) function in it, but I wasn't really sure what to do with the script on the page so I pretty much just copied it all to a blank main.cpp file and assumed everything would be ok.

Anyway, I've got things up and running for the most part, the only errors that my debug output is showing now are:

main.cpp(22): error C2065: 'MessageCallback' : undeclared identifier
main.cpp(31): error C2065: 'print' : undeclared identifier

which presumably means that I just need to find the class that defines these functions and include it in my main.cpp file (this is how I solved the same problem I was having with the assert() function - in this case I just got lucky and noticed that assert was being used and #included while I was looking through the scriptstdstring and scriptbuilder files). Of course, the problem with this is that short of looking through every header file in my MSVC installation I have no real way to find these (is there some kind of handy chart that lists all the members of the standard C++ classes, or do you suggest that I actually look through all the .h files so that I get a feel for them).

Also, I remember reading somewhere that the main() function must be declared to return an int type, but the sample code written seems to assume that the main() function is declared as void and MSVC10 does not give me any errors when I do this, so should I just assume that this bit of information is outdated?

Share this post

Link to post
Share on other sites
The MessageCallback and print functions should be implemented by you in the application.

The code for the print function is provided at the bottom of http://www.angelcode.com/angelscript/sdk/docs/manual/doc_hello_world.html

And the code for the MessageCallback is provided here http://www.angelcode.com/angelscript/sdk/docs/manual/doc_compile_script.html

As for searching for standard C and C++ functions and classes I usually go for Google :) There are several good sites that provide this information.

The main() function usually works both with returning 'void' or 'int'. Normally it is declared to return an int where the value represents the success or failure of the processing, but it is not required to return this. The same goes for the function arguments I believe. If you do not plan on interpreting any of the command line arguments, then you can probably declare the main function without any function parameters and the compiler will still accept it.


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!