2017-02-21 63 views
0

我尝试建立与QBSQBS AVR编译

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存在于项目和目录中。

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

回答

3

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

可以设置workingDirectory一个Command的对象,但通常不建议为你的命令应该是独立的工作目录,除非绝对必要的。

此外,您似乎正在复制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" 
    } 
} 
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)