• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

How to deal with common errors while compiling!

slavi

#define SLAVI32 _WIN32
Senator
Joined
Sep 9, 2015
Messages
681
Solutions
11
Reaction score
560
GitHub
slavidodo
Hey there,

As the title describes, this tutorial aims to give you a background about a programming topic, which is compiling.
This tutorial is targeted to people with none to beginner knowledge in programming. We'll be using visual studio.

The reason behind posting this, is that most people won't need to work with c++ or modify the code at all. So they can find difficulties compiling.
Disclaimer: The content here may refer to external websites where you can learn more about the issue and how to deal with it.

1. undefined reference to xxxxx
1.a What does it mean?
First of all, this is called a "linker error", you can notice that this error will show up after the code is generated, but not finished.​
It means that there is a function/variable/... declared but not defined.. That is, the compiler knows that there is such a function/variable BUT it can't find any further information about it (aka body/definition of the function).​
1.b When does it happen?
1. Simplest case, there is a function declared in (.h) but isn't defined in the (.cpp) file.
C++:
// player.h
class Player
{
public:
  Player(); // constructor
private:
  void doSomething(); // declaration
};

// player.cpp
Player::Player()
{
    doSomething(); // undefined reference (the function is not defined)
}

2. The common case, trying to link an external library.
For simplicity I'll refer to lua, and that we are trying to compile 'forgottenserver'​
If this error showed up, undefined reference to lua_pushnumber, that means that the compiler could find the declaration (in lua.h) but it couldn't find the linked library (lua5.1.lib).​
Clearly, we indicate that we haven't told the compiled that it will be able to find that specific file (lua5.1.lib).​
First of all, make sure that you have installed the lua library (which should be included within the​
To fix this issue, head to (Project -> Properties -> Linker -> Input -> Additional Dependencies) and add the file name (lua5.1.lib).​
Screenshot_8.png
 
Back
Top