user32882
user32882

Reputation: 5877

Basic SCons example throwing `Do not know how to make File target `helloworld' error

I'm trying to follow this tutorial to build a simple C program using SCons. I created a file called SConstruct which contains the following:

env = Environment() # construction environment
env.Program(target='helloworld', source=['helloworld.c']) # build targets

I created a file called helloworld.c which includes the following:

#include <stdio.h>

int main() 
{
    printf("Hello World.");
}

Then I tried building from Powershell as follows:

scons helloworld

Unfortunately I got the following output

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building terminated because of errors.
scons: *** Do not know how to make File target `helloworld` (..\scons-tutorial\helloworld). Stop.

I followed the steps in the tutorial very closely, so I'm not sure what else I can do at this point. What am I doing wrong here?

Upvotes: 0

Views: 1711

Answers (2)

dmoody256
dmoody256

Reputation: 583

The error message is because there is no helloworld target. Yes, you said target='helloworld', but SCons is making it easy for the the SConscripts to be portable, and the prefixes and suffix extensions are assumed to be added on during the build when the platform can be resolved.

This means that on Windows, where the PROGSUFFIX (program suffix) is .exe, you should type scons helloworld.exe to build the target. Note that all build output filepaths are implicitly targets.

If you wanted to make the scons helloworld a platform portable command for your build, you could use an alias:

helloworld_nodes = env.Program(target='helloworld', source=['helloworld.c']) # build targets
env.Alias('helloworld_app', helloworld_nodes)

now you could type scons helloworld_app on any platform and it would build the helloworld binary.

Upvotes: 2

user32882
user32882

Reputation: 5877

It turns out the instructions in Section 2.1 of this link were more accurate. It suffices to have the following in the SConstruct file:

Program(target='helloworld', source='helloworld.c') # build targets

Running a simple scons from the command line then works.

Upvotes: 0

Related Questions