1

I'm trying to run a c++ script from IDL using the CALL_EXTERNAL function. I've been able to get it to work without arguments, but when I try to add an arg, such as a single IDL LONG INT, IDL crashes. with the error:

% CALL_EXTERNAL: Error loading sharable executable.
                 Symbol: main, File = /home/inspired/workspace/TestCode/main.
                 so
                 /home/inspired/workspace/TestCode/main.so: wrong ELF class:
                 ELFCLASS64
% Execution halted at: TEST_EXTERNAL       7
  /home/inspired/IDLWorkspace/Analyze Data/test_external.pro
%                      $MAIN$    

The test code I'm using is as follows.

The C++ code:

#include <iostream>

int main(int argc, char *argv[]) {
    int temp = (int) strtod(argv[1], NULL);
    std:cout<<temp;
    return temp;
}

The IDL code:

pro test_external
 c= call_external('/home/inspired/workspace/TestCode/main.so','main', long(2), /AUTO_GLUE)
 print,c
end

This code is of course practice code, but if I can't get this to work, then there's no way I'll be able to pass a mixture of arrays, and values.

I am aware that IDL passes everything by reference unless stated otherwise. So I've tried both treating the passed argument as a pointer in the C++ code, and setting the /ALL_VALUE keyword to pass the arg as a value. Neither works resulting in the same error as above. I've read about "glue functions" but I have not been able to find a guide to making them (despite every source indicating that it's 'easy for most programmers'" >.>

Anyway, my options are as follows, and if you can help me with any, I'd be eternally grateful:

  1. Get this CALL_EXTERNAL function to work
  2. Have the C code grab the data it needs from memory somehow
  3. Rewrite everything in C++ (you don't need to help with this one)

Thanks in advance.

Kammeot
  • 469
  • 7
  • 18

1 Answers1

0

I think you are trying to mix 32-bit and 64-bit code. It looks like you are compiling your code as 64-bit, but you are running 32-bit IDL. To check this, IDL prints it when it launches or you can check manually:

IDL> print, !version.memory_bits
      64
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • I will check this on Monday. Just wanted to let you know that I haven't forgotten about this. – Kammeot Jul 07 '13 at 03:14
  • Ok, so my developer environment is compiling in 64 bit while the command line idl is compiling in 32 bit. I got that error message from the command line because the DE wasn't giving any useful errors. (it was just crashing). Anyway, I started IDL with the -64 tag to put it in 64 bit mode, and now it compiles. However, now it seems I'm getting a segmentation fault from the C++ shared library if I try to pass args. I guess this isn't really related to this question anymore, but how would i go about passing args to a shared Library without causing a segmentation fault? – Kammeot Jul 08 '13 at 14:01
  • It's fairly straightforward to pass arguments to a particular routine with `CALL_EXTERNAL`. Check the documentation for `CALL_EXTERNAL` (particularly the `VALUE` keyword) and the External Development Guide (*erg.pdf* in the *help/pdf* directory of the IDL distribution). – mgalloy Jul 08 '13 at 19:44
  • Yeah, I think I've got it coded correctly on the IDL end, now I'm having problems with the C++ side. I can't even call it in the terminal with arguments. – Kammeot Jul 09 '13 at 01:46