Home > Back-end >  Basic SCons example throwing `Do not know how to make File target `helloworld' error
Basic SCons example throwing `Do not know how to make File target `helloworld' error

Time:08-25

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?

CodePudding user response:

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.

CodePudding user response:

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:

env.Alias('helloworld_app', 'helloworld')

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

  • Related