【发布时间】:2016-09-29 20:40:38
【问题描述】:
我正在尝试使用 AMPL-API 将 AMPL 与 C/C++ 集成。我在 Eclipse 中创建了一个使用 MinGW CC 编译代码的 Makefile 项目。
这是我的 C++ 代码:
#include <iostream>
#include "ampl/ampl.h"
using namespace std;
int main() {
ampl::AMPL ampl;
// Read the model and data files.
std::string modelDirectory = "models";
ampl.read(modelDirectory + "/diet/diet.mod");
ampl.readData(modelDirectory + "/diet/diet.dat");
// Solve
ampl.solve();
// Get objective entity by AMPL name
ampl::Objective totalcost = ampl.getObjective("total_cost");
// Print it
std::cout << "Objective is: " << totalcost.value() << std::endl;
}
以下是我的 Makefile:
CC = g++
CFLAGS = -O2 -g -Wall -fmessage-length=0
INCLUDES = -I "C:\\Local\\AMPL\\amplide.mswin32\\amplide.mswin32\\amplapi\\include"
OBJS = AMPL.o
LIBS = -lampl1.2.2
TARGET = AMPL.exe
$(TARGET): $(OBJS)
$(CC) -L "./" -o $(TARGET) $(OBJS) $(LIBS)
AMPL.o: AMPL.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c AMPL.cpp
all: $(TARGET)
clean:
rm -f $(OBJS) $(TARGET)
我的项目目录的内容是:
- .settings/
- 型号/
- 饮食/
- 饮食.dat
- 饮食.mod
- 饮食/
- .cproject
- .project
- AMPL.cpp
- AMPL.exe
- AMPL.o
- ampl1.2.2.lib
- 生成文件
我有一台 32 位 Windows 7 机器,上面安装了 Eclipse Mars 2.0 和 Visual Studio 2015。每当我运行 exe 文件时,它都会说 MVCP100D.dll 丢失。我在网上查看,发现这个错误通常是在缺少 Visual C++ Redistributable 时出现的。但是我的系统上安装了可再发行组件。请帮我解决这个问题。
更新:我尝试在 Visual Studio 2015 上执行相同的代码,并且它也能够编译,但是我无法运行 *.exe 文件。它还说缺少 MVCP100D.dll。我不知道为什么会出现这个错误,请帮忙!!
更新: 下载更新版本在 Visual Studio 2015 中工作,但面临其他帖子中指定的单独问题:Undefined reference to (error) in C++ Eclipse but working in Visual Studio 2015
【问题讨论】:
-
MVCP100D.dll 是一个调试 dll(注意名称末尾的 D),与可再发行组件无关。您是在开发计算机上还是在另一台计算机上遇到此问题?更多详情:social.msdn.microsoft.com/Forums/en-US/…
-
感谢 Richard 的及时回复!这仅在我的开发计算机上发生。
标签: c++ eclipse windows-7 visual-studio-2015 ampl