【问题标题】:C++ programs using Octave libraries使用 Octave 库的 C++ 程序
【发布时间】:2017-01-08 23:10:20
【问题描述】:

我尝试在我的 Octave 的 c++ 项目库中使用。 不幸的是,我无法构建程序。 我使用的是 Windows 7 64 位、Octave3.6.4_gcc4.6.2 和 gcc 4.6.2。

我的步骤:

  1. 已下载 Octave3.6.4_gcc4.6.2.exe (http://sourceforge.net/projects/octave/files/Octave%20Windows%20binaries/Octave%203.6.4%20for%20Windows%20MinGW%20installer/Octave3.6.4_gcc4.6.2_20130408.7z/download)

我安装在 C:\Octave 中。我在环境变量PATH中添加了octave的bin文件夹地址。

  1. 已下载 mingw32-gcc-4.6.2-release-c,c++,fortran-sjlj-FINAL.7z 并安装在C盘。我已经将mingw的bin文件夹地址添加到环境变量PATH中了。

  2. 尝试编译简单示例 main.cpp(或来自http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html#Standalone-Programs的示例)

.

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

using namespace std;

int main() {

  return 0;
}
  1. 我使用了makefile:

.

OCTAVE_INCLUDE=C:\Octave\Octave3.6.4_gcc4.6.2\include\octave-3.6.4

all: test

clean:
    -rm test.o test

test: test.o
    mkoctfile --link-stand-alone -o test test.o

test.o: main.cpp
    g++ -c -I$(OCTAVE_INCLUDE) -I$(OCTAVE_INCLUDE)octave -o test.o main.cpp

所以,我们有

hdf5.h: 没有这样的文件或目录 regex.h: 没有这样的文件或目录

但它们在 C:\Octave\Octave3.2.4_gcc4.4.0\include\

我不明白我的错误在哪里。

【问题讨论】:

  • 好吧,你说文件的头文件在“C:\Octave\Octave3.2.4_gcc4.4.0\include\”,你告诉g++在“C: \Octave\Octave3.6.4_gcc4.6.2\include\octave-3.6.4" 和 "C:\Octave\Octave3.6.4_gcc4.6.2\include\octave-3.6.4octave",两者都不是 "C:\ Octave\Octave3.2.4_gcc4.4.0\include\".
  • Mike,我如何告诉编译器必要的头文件在 "C:\Octave\Octave3.2.4_gcc4.4.0\include\" 中?
  • 你已经这样做了! - 使用-I&lt;directory&gt; 选项。只需指定正确的&lt;directory&gt;(s)。
  • 我明白,但我不知道如何指定两个路径以包含在我的案例中
  • 使用多个-I&lt;dir&gt; 选项。编译器将按照指定的顺序搜索它们,直到成功或最终失败。看起来你基本上不了解如何使用 GCC 和 GNU Make,而且它超出了 Stackoverflow 的目的来解决这个问题。 Here is a fairly sound beginner's tutorial。对于权威文档,here is the GCC manualhere is the GNU Make manual

标签: c++ gcc octave


【解决方案1】:

我的问题的解决方案是我的 gcc 版本有问题。它似乎与用于编译 octave 的版本不兼容。

修正后的makefile如下:

OCTAVE_INCLUDE=C:\Octave\Octave3.6.4_gcc4.6.2\include

all: test

clean:
    -rm test.o test

test: test.o
    mkoctfile --link-stand-alone -o test test.o

test.o: main.cpp
    g++ -c -I$(OCTAVE_INCLUDE) -I$(OCTAVE_INCLUDE)\octave-3.6.4 -o test.o main.cpp

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 2012-03-04
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多