#include doesn't work

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

#include doesn't work

Post by Erato »

I've seen the 2CC-set use #include to import other files into the main .pnml file. Having seen how I almost couldn't read my own code anymore, I figured I want to give this a shot, but when I try to compile with NML v5850, I get the following error:

Code: Select all

Parsing ...Illegal character '#' (character code 0x23) at "MMT.pnml", line 32, column 1
(note: I've got a lot of comments, that's why it's 32, and not like 12.)

I'm using the following code:
[+] Spoiler

Code: Select all

// Define File
grf {
	grfid:	"EN\01\01";
	name:	string(STR_GRF_NAME);
	desc:	string(STR_GRF_DESC);
	version:	0;
	min_compatible_version: 0;
}
//Useable cargo
cargotable {
	PASS,
	TOUR
}

#include "src/template.nml"
#include "src/switch.nml"

//Imports trains
#include "src/MGV/HSST03.nml" //Power -
#include "src/MGV/MBAHN.nml" //Power -
#include "src/MGV/HSST100L.nml" //Year - Power -
#include "src/MGV/HSST100S.nml" //Year - Power -
#include "src/MGV/TRANSRAPID.nml" //Weight - Power -
#include "src/MGV/LINIMO.nml" //Power -
#include "src/MGV/UTM02.nml" //Power -
#include "src/MGV/ECOBEE.nml" //Power -
#include "src/MGV/CHANGSHA.nml" //Weight - Power -
#include "src/MGV/LINES1.nml" //Weight - Power -
#include "src/MGV/L0.nml" //Weight - Power -

#include "src/pass.nml"
What am I doing wrong and how can I fix it so that I can compile this?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: #include doesn't work

Post by Sylf »

#include lines are parsed by C pre-processor. 2cc uses the Makefile (and GNU make) to pre-process the pnml file and generate the nml file. If you want to use #include, you'll need to use make.
Some info at: http://dev.openttdcoop.org/projects/hom ... a_Makefile
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: #include doesn't work

Post by Alberth »

Actually, you need a C pre-processor program only. This usually gets distributed at a Linux system as "cpp". At other systems, ymmv.
Luckily, there is a simple 2nd option, namely a normal C or C++ compiler, like gcc. C compilation requires the source to be pre-processed as first step, so every C compiler has cpp available.

Make (and a Makefile) is a level on top of that. Basically, it's a list of build rules "make this output file from this list of input files, and use this command to do it." Since an input file can be an output file of another rule, you can chain build steps (step 1: "grf" from "nml", step 2: "nml" from "pnml"). make finds these chains and runs all commands required to build the final target.
For example, the commands that are run to build ogfx-industries:

Code: Select all

echo "[CPP] ogfx-industries.nml"
cc -D REPO_REVISION=5518 -D NEWGRF_VERSION=5518  -C -E -nostdinc -x c-header -o ogfx-industries.nml ogfx-industries.pnml
echo "[LNG] custom_tags.txt"
echo "VERSION        :v5518M (bb833d0eaca4)" > custom_tags.txt
echo "VERSION_STRING :v5518M (bb833d0eaca4)" >> custom_tags.txt
echo "TITLE          :OpenGFX+ Industries v5518M (bb833d0eaca4)" >> custom_tags.txt
echo "FILENAME       :ogfx-industries.grf" >> custom_tags.txt
echo "REPO_HASH      :bb833d0eaca4" >> custom_tags.txt
echo "NEWGRF_VERSION :5518" >> custom_tags.txt
echo "[NML] ogfx-industries.grf"
"~/bin/nmlc" -c --grf ogfx-industries.grf ogfx-industries.nml
echo "[BUNDLE] ogfx-industries"
if [ -e ogfx-industries ]; then rm -rf ogfx-industries; fi
mkdir ogfx-industries
for i in ogfx-industries.grf docs/readme.txt docs/license.txt docs/changelog.txt; do cp -rf $i ogfx-industries; done
echo "[BUNDLE TAR] ogfx-industries.tar"
"/usr/bin/tar" -cf ogfx-industries.tar ogfx-industries
All that is done by just typing "make". Second line is the c pre-processing step, then a lot of commands to make 'custom_tags.txt", the nmlc program is being run, and finally a tar file is constructed.
Being a retired OpenTTD developer does not mean I know what I am doing.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: #include doesn't work

Post by Transportman »

I once wrote a guide to set up a compile environment on Windows (as make and other commands are Linux commands).
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: #include doesn't work

Post by Erato »

Transportman wrote:I once wrote a guide to set up a compile environment on Windows (as make and other commands are Linux commands).
So, I followed it completely, and the test commands all work.
But when I compile, I get this error:

Code: Select all

E:\Games\NMLstuffs\Modern Maglev Trains>make
[CPP] MMT.nml
/bin/bash: cc: command not found
make: *** [MMT.nml] Error 127
According to the "echo $PATH" command, I have all the directories, apart from:
"/e/MinGW/msys/1.0/bin"
So, as the tutorial tells me, I make the following file:
.bashrc

Code: Select all

PATH="/e/MinGW/msys/1.0/bin:/e/MinGW/bin:/e/Games/NMLstuffs/Modern Maglev Trains:/c/Python27:$PATH"
// I also tried:

Code: Select all

PATH="/e/MinGW/msys/1.0/bin:$PATH"
(neither worked)
So I had a small problem prior to that; there was no /home/<USER> flolder, so I made it, not sure if that's a problem.

but I still get the same error when I use the "make" command.

What am I doing wrong?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: #include doesn't work

Post by Alberth »

You started a new bash after changing the .bashrc? The file gets read only when you start a new shell, thus making a change in that file does not affect any shell that is already running.

Make just invokes the programs at the standard path, so you can easily test by asking online help or a version to the cc program, like "cc --version"

Is there a cc command in that directory?
Can you run it yourself? ("/e/MinGW/msys/1.0/bin/cc --help" or so)

home dir creation should not be a problem.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: #include doesn't work

Post by Erato »

Alberth wrote:You started a new bash after changing the .bashrc? The file gets read only when you start a new shell, thus making a change in that file does not affect any shell that is already running.

Make just invokes the programs at the standard path, so you can easily test by asking online help or a version to the cc program, like "cc --version"

Is there a cc command in that directory?
Can you run it yourself? ("/e/MinGW/msys/1.0/bin/cc --help" or so)

home dir creation should not be a problem.
The cc command is unfortunately absent.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: #include doesn't work

Post by Transportman »

Are you sure your Python path is correct? It is the only one that would be on the C drive according to your path.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: #include doesn't work

Post by Sylf »

Transportman wrote:I once wrote a guide to set up a compile environment on Windows (as make and other commands are Linux commands).
Shameless plug. Here's my version that uses cygwin.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: #include doesn't work

Post by Erato »

Transportman wrote:Are you sure your Python path is correct? It is the only one that would be on the C drive according to your path.
Yes, I've checked and double-checked.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: #include doesn't work

Post by planetmaker »

Erato wrote:
Alberth wrote:You started a new bash after changing the .bashrc? The file gets read only when you start a new shell, thus making a change in that file does not affect any shell that is already running.

Make just invokes the programs at the standard path, so you can easily test by asking online help or a version to the cc program, like "cc --version"

Is there a cc command in that directory?
Can you run it yourself? ("/e/MinGW/msys/1.0/bin/cc --help" or so)

home dir creation should not be a problem.
The cc command is unfortunately absent.
The CC command is the mingw's synonym for gcc (or cpp). It needs to be in the search path as available in MinGW shell. Besides NML you also need GCC in order to build the project.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: #include doesn't work

Post by Transportman »

Sylf wrote:
Transportman wrote:I once wrote a guide to set up a compile environment on Windows (as make and other commands are Linux commands).
Shameless plug. Here's my version that uses cygwin.
Hopefully, you will be presented with a working YETI.tar after a few hours. It takes about 3 hours on my PC the very first time I compile YETI. After that, it's about a 2 minute job.
That sounds nice, one long compilation the first time, only a few minutes for every time after that. I would be interested to know how it would compare with my guide, maybe something to test one day.
Erato wrote:
Transportman wrote:Are you sure your Python path is correct? It is the only one that would be on the C drive according to your path.
Yes, I've checked and double-checked.
Okay, and your NML is really installed in e/Games/NMLstuffs/Modern Maglev Trains? Because I would suspect that that contains only the code of your NewGRF, and that NML itself is installed somewhere else.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: #include doesn't work

Post by 3iff »

I use mingw and bounced into the same problem with CC. I found adding the following line (before CC is used/called for the first time) fixes the problem.

CC = gcc

Hopefully, that will work for you too.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: #include doesn't work

Post by Erato »

3iff wrote:I use mingw and bounced into the same problem with CC. I found adding the following line (before CC is used/called for the first time) fixes the problem.

CC = gcc

Hopefully, that will work for you too.
This.

Thanks!
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: #include doesn't work

Post by 3iff »

Glad it worked. I spent about an hour on this problem when I encountered it...so I made a specific note for my future reference as I knew I would forget exactly what I had done (and why).
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 11 guests