tuxnsk / nodejs_libmodbus

libmodbus binding for nodejs
42 stars 66 forks source link

Does not work on a Mac OS X 10.9 64 bit #4

Closed chaser92 closed 8 years ago

chaser92 commented 10 years ago

Was unable to fix this problem. The library has linking problems with .dyld shared libraries (OS X .so equivalent). It builds yet crashes when any modbus function is called.

tuxnsk commented 10 years ago

I don't have OS X, writed only linux

2014/1/7 chaser92 notifications@github.com

Was unable to fix this problem. The library has linking problems with .dyld shared libraries (OS X .so equivalent). It builds yet crashes when any modbus function is called.

— Reply to this email directly or view it on GitHubhttps://github.com/tuxnsk/nodejs_libmodbus/issues/4 .

Contacts: http://tuxnsk.ru/

gizero commented 10 years ago

I have the same issue here... I'm investigating. I'll report back if I find a clue.

chaser92 commented 10 years ago

@gizero, I can help, because I need to fix this issue in order to work with this library (stuck with virtual machines without it). For now, take a look at binding.gyp file

nzfarmer1 commented 9 years ago

This works for me. Replace binding.gyp with this one. I also had to change python2 to python in package.json but I believe that can be done via configuration.

No doubt it could be improved as I am not a specialist with node-gyp or cmake

{
    'conditions': [
        [
            'OS=="mac"', {
                'targets': [
                    {
                        'target_name': 'modbus_binding',
                        'cflags': [
                            '-Wall',
                        ],
                    'xcode_settings': {
                        'OTHER_CFLAGS': [ '-ObjC' ],
                        'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++', '-v'],
                        'OTHER_LDFLAGS': ['-stdlib=libc++'],
                        'MACOSX_DEPLOYMENT_TARGET': '10.9',
                        'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 
                        },
                    'libraries': [
                        '../libmodbus/src/.libs/libmodbus.a',
                    ],
                        'include_dirs': [
                            './libmodbus/src/',
                        ],
                        'sources': [
                            './src/main.cpp'
                        ],
                    },
                ]
            },
        ],
        [
            'OS=="linux"', {
                'targets': [
                    {
                        'target_name': 'modbus_binding',
                        'cflags': [
                            '-Wall',
                        ],
                        'ldflags': [
                            '../libmodbus/src/.libs/modbus.o',
                            '../libmodbus/src/.libs/modbus-data.o',
                            '../libmodbus/src/.libs/modbus-rtu.o',
                            '../libmodbus/src/.libs/modbus-tcp.o',
                        ],
                        'include_dirs': [
                            './libmodbus/src/',
                        ],
                        'sources': [
                            './src/main.cpp'
                        ],
                    },
                ]
            },
        ]
    ]
}
aik8 commented 9 years ago

I am running OS X 10.9 and I cannot build it using your binding.gyp. However, with Node v0.10.37 and the following binding.gyp it seems to be working just fine. I will propose removing the 'OS=="linux"' condition altogether.

{
    'targets': [{
        'target_name': 'modbus_binding',
        'cflags': [
            '-Wall'
        ],
        'ldflags': [
            '../libmodbus/src/.libs/modbus.o',
            '../libmodbus/src/.libs/modbus-data.o',
            '../libmodbus/src/.libs/modbus-rtu.o',
            '../libmodbus/src/.libs/modbus-tcp.o'
        ],
        'include_dirs': [
            './libmodbus/src/'
        ],
        'sources': [
            './src/main.cpp'
        ]
    }]
}
nzfarmer1 commented 9 years ago

Perfect!

nzfarmer1 commented 9 years ago

John

At least we are getting a clean compile, but:

When I compile with this and run either master.js or master_native I get

mac02-4:examples andrew$ node master.js dyld: lazy symbol binding failed: Symbol not found: _modbus_new_tcp Referenced from: /Users/andrew/dev/node_modules/nodejs_libmodbus/build/Release/modbus_binding.node Expected in: dynamic lookup

When using my osx specific gyp file I get

mac02-4:examples andrew$ node master.js ERROR createMasterTcp: Undefined error: 0

mac02-4:examples andrew$ node master_native.js 61696

aik8 commented 9 years ago

I'll look into it.

bhadrip commented 8 years ago

+1 I am having the same issue.

Disminder commented 8 years ago

It helps to me:

brew install libmodbus and edit binding.gyp like this:

{
    'targets': [
        {
            'target_name': 'modbus_binding',
            'cflags': [
                '-Wall',
            ],
        'xcode_settings': {
            'OTHER_CFLAGS': [ '-ObjC' ],
            'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++', '-v'],
            'OTHER_LDFLAGS': ['-stdlib=libc++'],
            'MACOSX_DEPLOYMENT_TARGET': '10.9',
            'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 
            },
        'libraries': [
            '../libmodbus/src/.libs/libmodbus.dylib',
        ],
            'include_dirs': [
                './libmodbus/src/',
            ],
            'sources': [
                './src/main.cpp'
            ],
        },
    ]
}

Then ./make_libmodbus.sh && node-gyp configure --python=python && node-gyp build in node_modules/modbus Mac OS 10.11.4, Node 6.0.0. Now have

FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope

UPD: watch #26 for FATAL ERROR fix

Disminder commented 8 years ago

Fixed by https://github.com/tuxnsk/nodejs_libmodbus/commit/e49bc3e49ec914afa7450fa4b775f47fa7d0d30c