SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   #include doesn't include (https://forum.sa-mp.com/showthread.php?t=672735)

pollo97 26/02/2020 07:59 PM

#include doesn't include
 
Hi to everyone, i'm creating a project using the modular programming technique and I got this error:

Code:

core/systems/connection/login/core.pwn(6) : error 017: undefined symbol "InitializeForLogin"
Now there are two files, one is core.pwn and the other is functions.pwn
In the main.pwn I included the files in this way:

Code:


... other #include

#include "core/systems/connection/login/core.pwn"
#include "core/systems/connection/login/functions.pwn"

The code of core.pwn:
Code:

#include <YSI_Coding\y_hooks>

public OnPlayerConnect(playerid)
{
        InitializeForLogin(playerid);
    ....
}

The code of functions.pwn:
Code:

InitializeForLogin(playerid)
{
...
}

I tried to move the definition of "InitializeForLogin(playerid)" after "core" inclusion in the main, like this:
Code:

#include "core/systems/connection/login/core.pwn"
InitializeForLogin(playerid)
{
...
}

And works fine. So it seems is not including functions.pwn

What's wrong? :)



UPDATE:
I tried to modify this inclusion:
Code:

#include "core/systems/connection/login/functions.pwn"
Into:
Code:

#include "corewrong/systems/connection/login/functions.pwn"
corewrong folder doesn't exist and the compiler give me the error:
Code:

fatal error 100: cannot read from file: "corewrong/systems/connection/login/functions.pwn"
And it's fine, but when I change the file name with a wrong one, i get no error of "cannot read from file":
Code:

#include "core/systems/connection/login/wrong.pwn"
So it's seems the compiler isn't opening the file, I tried using either default compiler and Zeex's version.

insus100 27/02/2020 10:35 AM

Re: #include doesn't include
 
Try
PHP Code:

#include "/core/systems/connection/login/functions.pwn 


pollo97 27/02/2020 11:32 AM

Re: #include doesn't include
 
Quote:

Originally Posted by insus100 (Post 4132637)
Try
PHP Code:

#include "/core/systems/connection/login/functions.pwn 


It's working :) but why?
If I change also the core's inclusion in this way:
Code:

#include "/core/systems/connection/login/core.pwn"
#include "/core/systems/connection/login/functions.pwn"

It gives me the same error of before
Code:

error 017: undefined symbol "InitializeForLogin"
I'm confused :/


UPDATE:
I finally solved using this guide.
Code:

#include "core\systems\connection\login/core.pwn"
#include "core\systems\connection\login/functions.pwn"

The inclusion formatted in this way worked.

Nero_3D 27/02/2020 01:43 PM

Re: #include doesn't include
 
you could create a list file (-l in the compiler option) and see what the preprocessor does

but I think your problem is that you use forward slashes and the default compiler
Quote:

Originally Posted by ColeMiner (Post 2923599)
I suspect this is something to do with the length:

pawn Code:
_inc_files/scripts/staff/genera

As the include-guard would be called when using forward slashes (not a valid name, but that's the problem with forward slashes) is 31 characters. When using "\" the separators are correctly identified and you get this:

pawn Code:
_inc_general

Thus, if you have another file called "general" in another folder, this one won't get included because the compiler thinks it already has been. This sounds like the best candidate for the problem (ignore what I started saying about length) - it MAY crash if you include code here that is needed, but it doesn't get included because of the mix-up with include guards.

I don't always recommend using "\" for exactly this reason - which to use varies by use-case. In your case you may want to instead use "/" since it worked anyway (just be aware of long directory chains).

Zeex's compiler doesn't automatically generate include guards so this won't be a problem there, but that can cause other issues if your files don't contain explicit include guards as required.



All times are GMT. The time now is 03:33 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.