简体   繁体   English

使用混合的C / C ++源文件构建NodeJS插件

[英]Building a NodeJS addon with mixed C/C++ source files

I'm trying to build a NodeJS addon from mixed C/C++ source. 我正在尝试从混合的C / C ++源构建一个NodeJS插件。 I want to avoid building the C code as separate shared library, though this is a partial solution. 我想避免将C代码构建为单独的共享库,尽管这是部分解决方案。

I get the error: 我得到错误:

Cannot guess how to process src:///home/chris/Dropbox/cbackend/data.c 
(got mappings ['.C', '.cc', '.cpp', '.c++', '.cxx'] 
in <class 'cxx.cxx_taskgen'>) -> try conf.check_tool(..)?

when I try to build it. 当我尝试构建它时。 If I rename the .c file as .cc and change the wscript appropriately it all work fine. 如果我将.c文件重命名为.cc并适当地更改wscript,则一切正常。

I've tried adding a 'compiler_c' to the wscript, but it doesn't seem to be available. 我曾尝试在wscript中添加一个'compiler_c',但它似乎不可用。

Here's the wscript: 这是wscript:

import os
import Options

srcdir = '.'
blddir = 'build'
VERSION = '0.3.0'

def set_options(opt):
  opt.tool_options('compiler_cxx')

def configure(conf):
  conf.check_tool('compiler_cxx')
  conf.check_tool('node_addon')

  conf.env.append_value('CCFLAGS', ['-O3'])
  conf.env.append_value('CXXFLAGS', ['-O3'])
  if Options.platform == 'darwin': conf.env.append_value('LINKFLAGS', ['-undefined', 'dynamic_lookup'])

def build(bld):
  obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  obj.target = 'cbackend'
  obj.source = 'cbackend.cc data.c'
  obj.uselib = ['NODE']

I was given the solution on a mailing list. 在邮件列表中给了我解决方案。

The plain C compiler is called 'compiler_cc' in NodeJS, not 'compiler_c' as in the WAF docs. 普通的C编译器在NodeJS中称为“ compiler_cc”,而不是WAF文档中的“ compiler_c”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM