0

我尝试用 qbs 构建简单的项目

import qbs
Project {
    name: "simple"
    Product {
        name: "micro"
        type: "obj"
        Group {
            name: "sources"
            files: ["main.c", "*.h", "*.S"]
            fileTags: ['c']
        }
        Rule {
            inputs: ["c"]
            Artifact {
                fileTags: ['obj']
                filePath: input.fileName + '.o'
            }
            prepare: {
                var args = [];
                args.push("-g")
                args.push("-Os")
                args.push("-w")
                args.push("-fno-exceptions")
                args.push("-ffunction-sections")
                args.push("-fdata-sections")
                args.push("-MMD")
                args.push("-mmcu=atmega328p")
                args.push("-DF_CPU=16000000L")
                args.push("-DARDUINO=152")
                args.push("-IC:/Programs/arduino/hardware/arduino/avr/cores/arduino")
                args.push("-IC:/Programs/arduino/hardware/arduino/avr/variants/standard")
                args.push("-c")
                args.push(input.fileName)
                args.push("-o")
                args.push(input.fileName + ".o")
                var compilerPath = "C:/Programs/arduino/hardware/tools/avr/bin/avr-g++.exe"
                var cmd = new Command(compilerPath, args);
                cmd.description = 'compiling ' + input.fileName;
                cmd.highlight = 'compiler';
                cmd.silent = false;
                console.error(input.baseDir + '/' + input.fileName);
                return cmd;
            }
        }
    }
}

我得到错误

compiling main.c
C:/Programs/arduino/hardware/tools/avr/bin/avr-g++.exe -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD "-mmcu=atmega328p" "-DF_CPU=16000000L" "-DARDUINO=152" -IC:/Programs/arduino/hardware/arduino/avr/cores/arduino -IC:/Programs/arduino/hardware/arduino/avr/variants/standard -c main.c -o main.c.o
avr-g++.exe: main.c: No such file or directory
avr-g++.exe: no input files
Process failed with exit code 1.
The following products could not be built for configuration qtc_avr_f84c45e7-release:
    micro

我错了什么?

文件 main.c 存在于项目和目录中。

如果我从命令提示符启动此命令,我不会收到错误消息。

4

2 回答 2

3

简而言之,你需要input.filePath在 -c 和 -o 之后通过,而不是input.fileName. 不能保证调用的命令的工作目录就是您的源目录的工作目录。

可以设置Command对象的 workingDirectory,但通常不建议这样做,因为您的命令应该独立于工作目录,除非绝对必要。

此外,您似乎在复制 cpp 模块的功能。相反,您的项目应如下所示:

import qbs
Project {
    name: "simple"
    Product {
        Depends { name: "cpp" }
        name: "micro"
        type: "obj"
        Group {
            name: "sources"
            files: ["main.c", "*.h", "*.S"]
            fileTags: ['c']
        }
        cpp.debugInformation: true // passes -g
        cpp.optimization: "small" // passes -Os
        cpp.warningLevel: "none" // passes -w
        cpp.enableExceptions: false // passes -fno-exceptions
        cpp.commonCompilerFlags: [
            "-ffunction-sections",
            "-fdata-sections",
            "-MMD",
            "-mmcu=atmega328p"
        ]
        cpp.defines: [
            "F_CPU=16000000L",
            "ARDUINO=152"
        ]
        cpp.includePaths: [
            "C:/Programs/arduino/hardware/arduino/avr/cores/arduino",
            "C:/Programs/arduino/hardware/arduino/avr/variants/standard
        ]
        cpp.toolchainInstallPath: "C:/Programs/arduino/hardware/tools/avr/bin"
        cpp.cxxCompilerName: "avr-g++.exe"
    }
}
于 2017-02-22T07:25:59.813 回答
0

它对 args.push("-c") args.push(input.filePath) at you args.push(input.fileName) args.push("-o") args.push(output.filePath)你有用 args.push(input.fileName)

于 2017-05-23T19:48:46.783 回答