0

Building a native module for Node.js under Cygwin / Windows:

I have a monkey.cc file with this:

#include <monkey/monkey.h>

running

node-waf configure build

I get the following

'configure' finished successfully (0.351s)
Waf: Entering directory `/usr/src/build'
[2/2] cxx_link: build/default/monkey_1.o -> build/default/monkey.node build/default/libmonkey.dll.a
Creating library file: default/libmonkey.dll.a

then the following error:

default/monkey_1.o:/usr/src/build/../monkey.cc:144: undefined reference to `_monkeyFoo'

monkeyFoo is defined in monkey.h which is in a directory named monkey. I am running the above command from the directory containing monkey directory and monkey.cc file.

EDIT:

wscript, which is the python script that node-waf runs looks like this:

import os

srcdir = '.'
blddir = './build'
VERSION = '0.0.2'

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

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

def build(bld):
  monkey = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  monkey.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-L/usr/lib", "-lssl"]
  monkey.chmod = 0755
  monkey.target = 'monkey'
  monkey.source = 'monkey.cc'

What am I missing???

Tom
  • 7,994
  • 8
  • 45
  • 62
  • I have added the build script. There is nothing wrong with the code as this is existing code that I'm just trying to compile. I just need to get things in the right place! – Tom Jul 03 '11 at 02:10

2 Answers2

3

That's a linker error, not a compiler error. Do you have a definition for the function? (Not just a declaration.) And are you sure it's being linked in?

Shirik
  • 3,631
  • 1
  • 23
  • 27
  • Thanks, that's helpful. I do have the definitions, but they must be in the wrong place. How should this be set up exactly? – Tom Jul 03 '11 at 02:25
  • I think I am misunderstanding the meaning of the import statement. When I put the header and definition files into the same directory as monkey.cc, and change the import to simply 'monkey.h' then it says no such file or directory. So I am definitely barking up the wrong tree... – Tom Jul 03 '11 at 02:29
  • If the function definition isn't in monkey.cc, then you need to list that as one of the source files that is compiled. (I am not familiar with the build system you are using.) – Shirik Jul 03 '11 at 02:33
  • The function definition is actually in a library which is installed into cygwin through the package manager. I could dig up the source from elsewhere and try that way, but I get the feeling this is supposed to compile against binaries using the header files.. does that sound right? Thanks for your help. – Tom Jul 03 '11 at 02:36
  • notice the /Lusr/lib in the build script. (no I'm not familiar with it either!) Is this where its supposed to look for compiled libraries do you think? – Tom Jul 03 '11 at 02:38
  • either you've to specify the .cc file in your source file to be compiled or has to specify the linker where the definition for the function lies (probably an external pre-compiled library) – sarat Jul 03 '11 at 05:49
0

Add monkey.lib='crypto' in the wscript.

Tom
  • 7,994
  • 8
  • 45
  • 62