如何在scons中更改工作目录

时间:2016-01-24 09:45:00

标签: directory makefile ld scons

我有一个使用 make 构建的项目,但我想转移到 scons

但是,我无法在scons中链接目标文件,所以我想知道如何更改 scons 中的工作目录。

我真正想要的是

make -C $(OBJECTDIRECTORY) -f $(SOURCEDIRECTORY)./Makefile InternalDependency

这是我的Makefile中的一行,效果很好。

然而,当scons构建我的项目时,它确实

x86_64-pc-linux-ld -o build/kernel32/kernel32.elf -melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200 build/kernel32/asmUtils.o build/kernel32/cpu.o build/kernel32/main.o build/kernel32/memory.o build/kernel32/pageManager.o build/kernel32/utils.o

并收到错误,

x86_64-pc-linux-ld: cannot find main.o

。即使我手动在shell中执行相同的命令,我也遇到了同样的错误。

但是,如果我转向构建/ kernel32,并手动执行

x86_64-pc-linux-ld -o kernel32.elf -melf_i386 -T ../../elf_i386.x -nostdlib -e main -Ttext 0x10200 main.o cpu.o memory.o pageManager.o utils.o asmUtils.o

它有效。

我的假设是ld无法链接某些上层目录中的目标文件。

那么,有没有办法像Make的“-C”选项那样做? 或者在scons中的任何其他解决方法?

这是我的 SConscript SConsctruct

在项目根目录中,

#SConstruct

build_dir = 'build'

# Build
SConscript(['src/SConscript'], variant_dir = build_dir, duplicate = 0)

# Clean
Clean('.', build_dir)

在src目录中

#SConscript for src
SConscript(['bootloader/SConscript',
        'kernel32/SConscript'])

在kernel32目录

#SConscript for kernel32
import os, sys

# Build entry
env_entry = Environment(tools=['default', 'nasm'])

target_entry = 'entry.bin'

object_entry = 'entry.s'

output_entry = env_entry.Object(target_entry, object_entry)

# Compile CPP
env_gpp_options = {
    'CXX'       : 'x86_64-pc-linux-g++',
    'CXXFLAGS'  : '-std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti',
    'LINK'        : 'x86_64-pc-linux-ld',
    'LINKFLAGS'   : '-melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200',
}
env_gpp = Environment(**env_gpp_options)
env_gpp.Append(ENV = {'PATH' : os.environ['PATH']})

object_cpp_list = Glob('*.cpp')

for object_cpp in object_cpp_list:
    env_gpp.Object(object_cpp)

# Compile ASM
env_nasm = Environment(tools=['default', 'nasm'])
env_nasm.Append(ASFLAGS='-f elf32')

object_nasm_list = Glob('*.asm')

for object_nasm in object_nasm_list:
    env_nasm.Object(object_nasm)

# Find all object file
object_target_list = Glob('*.o')
object_target_list.append('entry.bin')

# Linking
env_link_target = 'kernel32.elf'

env_gpp.Program(env_link_target, object_target_list)

请告诉我。谢谢。

“--tree = prune”的日志是

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
x86_64-pc-linux-ld -o build/kernel32/kernel32.elf -melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200 build/kernel32/asmUtils.o build/kernel32/cpu.o build/kernel32/main.o build/kernel32/memory.o build/kernel32/pageManager.o build/kernel32/utils.o build/kernel32/entry.bin
+-.
  +-SConstruct
  +-build
  | +-src/SConscript
  | +-build/bootloader
  | | +-src/bootloader/BootLoader.asm
  | | +-src/bootloader/SConscript
  | | +-build/bootloader/bootloader.bin
  | |   +-src/bootloader/BootLoader.asm
  | |   +-/usr/bin/nasm
  | +-build/kernel32
  |   +-src/kernel32/SConscript
  |   +-src/kernel32/asmUtils.asm
  |   +-build/kernel32/asmUtils.o
  |   | +-src/kernel32/asmUtils.asm
  |   | +-/usr/bin/nasm
  |   +-src/kernel32/cpu.cpp
  |   +-build/kernel32/cpu.o
  |   | +-src/kernel32/cpu.cpp
  |   | +-src/kernel32/cpu.hpp
  |   | +-src/kernel32/types.hpp
  |   | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-g++
  |   +-build/kernel32/entry.bin
  |   | +-src/kernel32/entry.s
  |   | +-/usr/bin/nasm
  |   +-src/kernel32/entry.s
  |   +-build/kernel32/kernel32.elf
  |   | +-[build/kernel32/asmUtils.o]
  |   | +-[build/kernel32/cpu.o]
  |   | +-build/kernel32/main.o
  |   | | +-src/kernel32/main.cpp
  |   | | +-src/kernel32/cpu.hpp
  |   | | +-src/kernel32/memory.hpp
  |   | | +-src/kernel32/types.hpp
  |   | | +-src/kernel32/utils.hpp
  |   | | +-src/kernel32/pageManager.hpp
  |   | | +-src/kernel32/page.hpp
  |   | | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-g++
  |   | +-build/kernel32/memory.o
  |   | | +-src/kernel32/memory.cpp
  |   | | +-src/kernel32/memory.hpp
  |   | | +-src/kernel32/pageManager.hpp
  |   | | +-src/kernel32/page.hpp
  |   | | +-src/kernel32/types.hpp
  |   | | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-g++
  |   | +-build/kernel32/pageManager.o
  |   | | +-src/kernel32/pageManager.cpp
  |   | | +-src/kernel32/pageManager.hpp
  |   | | +-src/kernel32/page.hpp
  |   | | +-src/kernel32/types.hpp
  |   | | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-g++
  |   | +-build/kernel32/utils.o
  |   | | +-src/kernel32/utils.cpp
  |   | | +-src/kernel32/utils.hpp
  |   | | +-src/kernel32/types.hpp
  |   | | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-g++
  |   | +-[build/kernel32/entry.bin]
  |   | +-/home/xaliver/BuildTools/cross/bin/x86_64-pc-linux-ld
  |   +-src/kernel32/main.cpp
  |   +-[build/kernel32/main.o]
  |   +-src/kernel32/memory.cpp
  |   +-[build/kernel32/memory.o]
  |   +-src/kernel32/pageManager.cpp
  |   +-[build/kernel32/pageManager.o]
  |   +-src/kernel32/utils.cpp
  |   +-[build/kernel32/utils.o]
  +-src
    +-src/SConscript
    +-src/bootloader
    | +-src/bootloader/BootLoader.asm
    | +-src/bootloader/SConscript
    +-src/kernel32
      +-src/kernel32/SConscript
      +-src/kernel32/asmUtils.asm
      +-src/kernel32/cpu.cpp
      +-src/kernel32/cpu.hpp
      +-src/kernel32/entry.s
      +-src/kernel32/main.cpp
      +-src/kernel32/memory.cpp
      +-src/kernel32/memory.hpp
      +-src/kernel32/page.hpp
      +-src/kernel32/pageManager.cpp
      +-src/kernel32/pageManager.hpp
      +-src/kernel32/types.hpp
      +-src/kernel32/utils.cpp
      +-src/kernel32/utils.hpp
scons: building terminated because of errors.

0 个答案:

没有答案