1

I am trying to get the Dart native extension example from this page to work.

http://www.dartlang.org/articles/native-extensions-for-standalone-dart-vm/

I am on Windows. I downloaded and extracted dart to C:\Program Files\dart

I checked out dartsSVN into C:\Projects\dartSVN so I can get the sample_extention project but when I open it the analyzer throws these problems:

"Target of URI does not exist: 'dart-ext:sample_extension'"

and

"Native functions can only be declared in the SDK and code that is loaded through native extensions"

and when i try to run it i get

"cannot find extension library 'file:///C:/Projects/Dart/sample_extension/bin/sample_synchronous_extension.dart': Error: line 7 pos 1: library handler failed import 'dart-ext:sample_extension';

'file:///C:/Projects/Dart/sample_extension/bin/test_sample_synchronous_extension.dart': Error: line 7 pos 1: library handler failed import 'sample_synchronous_extension.dart';"

What am I doing wrong?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
H.R.
  • 496
  • 4
  • 14

1 Answers1

4

You can ignore analyzer error this time. It seems like a bug/issue with current Dart version.

The error "cannot find extension library... means that Dart VM can not find the "sample_extension.dll" file inside your project folder. You must compile the C++ source code of the sample by yourself to generate the library (dll under Windows).

The article about native extensions has a section called Building on Windows. Just follow the instructions.

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
  • Thank you for your help! since im new i cant click arrow up :/ :) – H.R. May 10 '13 at 14:33
  • done that "copy the DLL to the correct directory, relative to the Dart library part of the extension" i would have thought that the correct dir is the bin folder where i have my .dart files. but sill i get the same msg ;( – H.R. May 10 '13 at 15:27
  • @user1176557 `bin` folder is ok to me ("Command-line application" created with the Editor wizard and with the "Generate sample content" option checked) – Juan Mellado May 10 '13 at 19:02
  • I've done the same. Created "command line app" with "sample content". Build the dll. Copied dll it into every folder of the project. .. i know i know.. I checked that everything is 32bit (win64 but java&dart&dll 32) – H.R. May 10 '13 at 21:40
  • Wired: I **moved** all files from bin into package, and the errors inside the dart files are gone. Instead I get test_sync `Breaking on exception: type 'bool' is not a subtype of type 'void' of 'function result'.` and `Breaking on exception: 'file:///C:/Projects/Dart/sample_extension/bin/packages/sample_asyn....dart': Error: line 33 pos 3: cannot resolve class name 'SendPort' from 'RandomArray' ` Do I need to add additional packages to run native extensions, or is the error bc its not supposed to be in a package? – H.R. May 10 '13 at 21:58
  • @H.R. Current Dart code on SVN seems to be a bit old. Add `import "dart:isolate";` to remove the `cannot resolve class name 'SendPort'` error. The `checkCorrelation` function doesnt't need the `return` statement. Also, `Expect` was removed from SDK... File an issue to the Dart team better. [dartbug.com](http://dartbug.com) – Juan Mellado May 10 '13 at 23:18
  • cool, will try it out, and Issue [10590](https://code.google.com/p/dart/issues/detail?id=10590) reported ! and can you tell me why I have to move the files into the package folder for it to work? – H.R. May 11 '13 at 00:23
  • 1
    The sample_extension sample has been updated, to have the type errors pointed out above fixed. We are still deciding what to do about the fact that the editor does not like the "native" keyword, and complains.One reason why compiling the DLL separately, and putting it in the directory with the extension's dart file, might break is if the linking to the dart library is broken. Your DLL should link against the .lib file created when compiling dart. Then at runtime, when it is loaded by the dart.exe, it should successfully link with the dart library in the dart.exe. – William Hesse May 14 '13 at 11:22