如何在不安装Octave的情况下创建简单的Octave可分发文件 [英] How do I create a simple Octave distributable without installing Octave

查看:134
本文介绍了如何在不安装Octave的情况下创建简单的Octave可分发文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于该主题的Octave文档既令人生畏又稀疏.

The Octave documentation on this subject is both intimidating and sparse.

我不知道还有什么地方可以记录我找到的解决方案,所以我在这里发布.如果这不合适,我深表歉意,但我想帮助下一个人.

I did not know where else to document the solution I found, so I am posting here. I apologize if that's inappropriate, but I want to help the next guy.

以下解决方案适用于可分发的简单Windows.

The following solution is for a simple windows distributable.

用例:
一个解决方案是在Octave 3.2.4中开发的,需要将其分发给几乎没有计算机技能的最终用户.安装和解释Octave是不可能的,解决方案必须是一键式"或"brain-dead-simple".

Use Case:
A solution is developed in Octave 3.2.4, and needs to be distributed to end-users with few computer skills. Installing and explaining Octave is impossible, the solution must be "one-click" or "brain-dead-simple."

已知问题:
由于file_in_path.m错误,imread在3.2.4中失败.您将需要将文件file_in_path.m更新为以下文件(只需替换它):

Known Issues:
imread fails in 3.2.4 because file_in_path.m is wrong. You will need to update the file file_in_path.m to the following (just replace it):

function name=file_in_path(p,file)
  idx=[1 findstr(p,pathsep) length(p)+1];
  for i=1:length(idx)-1
    if idx(i+1)-idx(i)<=1
      dir=strcat(pwd,"/");
    else
      dir=p(idx(i)+1:idx(i+1)-1);
    end
    name = fullfile(dir, file);
    fid = fopen(name,"r");
    if fid >= 0
      fclose(fid);
      return
    end
  end
  fid = fopen(file,"r");
  if fid >= 0,
    fclose(fid);
    name=file;
    return
  end
  name=[]; 

推荐答案

解决方案:使用mkoctfile创建可分发的exe,并将该exe与核心Octave文件以及其他必要的.oct和.m文件打包在一起.

Solution: Create a distributable exe using mkoctfile, and package this exe with the core Octave files, and other .oct and .m files as necessary.

第1步:创建独立的可执行文件.

您可以在这里看到有效的代码: http://www.gnu.org/software/octave/doc/interpreter/Standalone- Programs.html

You can see code that works here: http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html

特别是文件"embedded.cc".

Particularly the file "embedded.cc".

我将该文件简化如下:

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>

int
main (int argc, char *argvc[])
{
  string_vector argv (2);
  argv(0) = "embedded";
  argv(1) = "-q";

  octave_main (2, argv.c_str_vec(), 1);

  octave_value_list in = octave_value (argvc[1]);
  octave_value_list out = feval ("your_custom_m_file", in);

  if (!error_state && out.length () > 0)
    {
    }
    else
    {
        std::cout << "invalid\n";
    }

  return 0;
}

使用命令构建该文件

mkoctfile --link-stand-alone embedded.cc -o embedded

它可能会发出警告,但是只要不引发错误,您就可以了.将会生成文件Embedded.exe,并且可以运行该文件.唯一的问题是它将缺少使八度音阶很棒的所有优点.您将必须提供这些内容.

It may throw warnings, but as long as it throws no errors, you should be fine. The file embedded.exe will be built, and can be run. The only issue is that it will lack all the goodies that make octave awesome. You will have to provide those.

第2步:创建分发文件夹

您将需要创建许多Octave文件的副本.我建议专门为此目录.至少,您将需要\ bin中所有或大多数DLL的副本.此外,将您的可分发可执行文件放在此目录中.

You will need to create a copy of many of the Octave files. I suggest a directory specifically for this. At a minimum, you will need a copy of all or most of the DLLs in \bin. Additionally, place your distributable executable in this directory.

第3步:其他文件乱码

您现在需要找出运行.m脚本所需的其他文件.您可以通过将\ oct \ i686-pc-mingw32 * .oct和\ share \ octave \ 3.2.4 \ m \ * \ *.m复制到分发目录来简化此步骤,尽管这可能会过大,并且实际上不会防止重击.

You will now need to find out what other files will be necessary to run your .m script. You can simplify this step by copying \oct\i686-pc-mingw32*.oct and \share\octave\3.2.4\m\*\*.m to the distribution directory, although this will be overkill, and will not actually prevent the whack-a-mole step.

现在,您必须扮演w鼠,或具有悠久历史的传统,例如我的同伴在哪里,哟?"

Now, you must play whack-a-mole or the time-honored tradition of "where my includes be at, yo?"

  1. 打开一个cmd提示符,然后导航到您的分发文件夹.
  2. 摆脱任何有用的PATH字符串.您的客户不会有他们.
  3. 尝试运行程序Embedded.exe.您将收到类似以下的错误:

  1. Open a cmd prompt and navigate to your distribution folder.
  2. Get rid of any useful PATH strings. Your customers won't have them.
  3. Attempt to run the program embedded.exe. You will get an error such as the following:

embedded.exe
错误:第83行第22列附近的"max"未定义
错误:评估参数列表元素编号1
错误:评估参数列表元素编号1
错误:从以下位置调用:
错误:第83行第3列的T:\ sms \ Development \ research \ c2 \ disttest \ strcat.m
错误:第5行第10列T:\ sms \ Development \ research \ c2 \ disttest \ file_in_path.m
错误:第50行第6列的T:\ sms \ Development \ research \ c2 \ disttest \ imread.m

embedded.exe
error: `max' undefined near line 83 column 22
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error: T:\sms\Development\research\c2\disttest\strcat.m at line 83, column 3
error: T:\sms\Development\research\c2\disttest\file_in_path.m at line 5, column 10
error: T:\sms\Development\research\c2\disttest\imread.m at line 50, column 6

  • A 在八度安装中搜索"max".该文件将是.oct或.m文件.在这种情况下,它是一个.oct文件,最大为oct.将其复制到您的分发目录.

  • A Search in your Octave installation for "max". It will either be a .oct or a .m file. In this case, it is a .oct file, max.oct. Copy it to your distribution directory.

    B 您搜索诸如"min"之类的明显内容,但没有结果.这是因为可加载函数"min"位于.oct文件"max.oct"中.制作一份最大十进制数的副本,并将其重命名为最小十进制数.现在可以使用了.您怎么知道功能在哪里?我不知道.它们中的大多数都位于明显的位置,例如min的"max.oct"和"ifft2.oct"的"fft2.oct".祝一切顺利.

    B You search for something obvious like "min", and get no results. This is because the Loadable Function "min" is in the .oct file "max.oct". Make a copy of max.oct, and rename it to min.oct. It will work now. How do you know where the functions are? I'm not sure. Most of them are in obvious places like "max.oct" for min, and "fft2.oct" for "ifft2.oct". Good luck with all that.

    重复执行直到可执行文件运行.

    Repeat until your executable runs.

    这篇关于如何在不安装Octave的情况下创建简单的Octave可分发文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆