Scons Hierarchical Builds with Repository directory

筅森魡賤 提交于 2019-12-22 01:09:44

问题


I have an SCons project set up as follows:

proj/
    SConstruct
    src/
        c/
        h/
    app1/SConscript
    app2/SConscript
    ...

All source/header files for each application are located in src/c and src/h.


  1. At first step I created a SConstruct in app1 which use the Repository function.

...

src=Split("main.c first.c second.c")

env = Environment(CC='g++', CCFLAGS=['-O0', '-ggdb'], CPPPATH=['.'])

env.Program('appone', src)

Repository("../src/c", "../src/h")

All works fine. scons found all necessary source/header files from repository to build the appone application.


But if I try to build appone hierarchical it will not work :-(

I renamed app1/SConstruct to app1/SConscript and put

SConscript('app1/SConscript')

into proj/SConstruct

Now I get following error:

scons: *** [app1/main.o] Source `app1/main.c' not found, needed by target `app1/main.o'.

How do I configure my proj/SConstruct or proj/app1/SConscript to search for all source files in my Repository directory?


回答1:


SCons is looking for your source files in the app1 directory. If you specify the sources like this:

src=Split("#main.c #first.c #second.c")

then scons will search the Repositories for the source files.

A couple extra thoughts:

  1. You may want main.c to be in the app1 directory to avoid conflicts with main.c for other executables. In this case, remove the # from main.c in your source list.

  2. It's probably a good idea to define the Repositories in your top-level SConstruct if multiple apps share the repositories.

  3. It's often useful to build libraries from the shared sources so that unit tests can have their own main functions, but link the same sources as your apps (or so apps can share common modules). It may be easier to do this by putting SConscripts in the shared repository directory to build common libraries. Beyond the scope of this question, but something to consider as your project grows.



来源:https://stackoverflow.com/questions/4043689/scons-hierarchical-builds-with-repository-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!