首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >qbs avr编译

qbs avr编译
EN

Stack Overflow用户
提问于 2017-02-21 11:33:40
回答 2查看 389关注 0票数 0

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

代码语言:javascript
复制
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;
            }
        }
    }
}

我会犯错误

代码语言:javascript
复制
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存在于项目和目录中。

如果从命令提示符启动此命令,则不会出现错误。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-22 07:25:59

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

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

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

代码语言:javascript
复制
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"
    }
}
票数 3
EN

Stack Overflow用户

发布于 2017-05-23 19:48:46

这是工作args.push("-c") args.push(input.filePath) at you args.push(input.fileName) args.push("-o") args.push(output.filePath)at you args.push(input.fileName)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42366163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档