2016-06-02 3 views
1

AMPLをC/C++に統合しようとしていますが、Eclipse Mars 2.0のWindows-7でAMPL-APIを使用しています。 EclipseのMakefileプロジェクトを作成しました。このプロジェクトでは、MinGW CCを使用してサンプルディレクトリにある最初のサンプルコードをコンパイルします。C++ Eclipseで未定義の参照ですが、Visual Studioで作業しています2015

firstexample.cpp:

#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; 
     // Get objective entity by AMPL name 
     ampl::Objective totalcost = ampl.getObjective("total_cost"); 
     // Print it 
     std::cout << "Objective is: " << totalcost.value() << std::endl; 

     // Reassign data - specific instances 
     ampl::Parameter cost = ampl.getParameter("cost"); 
     cost.setValues(new Tuple[2]{ ampl::Arg("BEEF"), ampl::Arg("HAM")}, new Arg[2]{ 5.01, 4.55 }, 
            2); 
     std::cout << "Increased costs of beef and ham." << std::endl; 

     // Resolve and display objective 
     ampl.solve(); 
     std::cout << "New objective value: " << totalcost.value() << std::endl; 

     // Reassign data - all instances 
     ampl::Arg elements[8]{ 3, 5, 5, 6, 1, 2, 5.01, 4.55 }; 
     cost.setValues(elements); 

     std::cout << "Updated all costs." << std::endl; 

     // Resolve and display objective 
     ampl.solve(); 
     std::cout << "New objective value: " << totalcost.value() << std::endl; 

     // Get the values of the variable Buy in a dataframe object 
     Variable buy = ampl.getVariable("Buy"); 
     ampl::DataFrame df; 
     df = buy.getValues(); 
     // Print them 
     df.print(); 
     ampl::DataFrame df2; 
     // Get the values of an expression into a DataFrame object 
     df2 = ampl.getData("{j in FOOD} 100*Buy[j]/Buy[j].ub"); 
     // Print them 
     df2.print(); 
} 

Following is my Makefile:

CC = g++ 

CFLAGS = -O2 -g -Wall -fmessage-length=0 

INCLUDES = -I "C:\\Local\\AMPL\\AMPL32\\amplapi32\\include" 

OBJS = AMPL.o 

LFLAGS = -L "C:\\Local\\AMPL\\AMPL32\\amplapi32\\lib" 

LIBS = -lampl1.2.2 

TARGET = AMPL.exe 

$(TARGET): $(OBJS) 
    $(CC) $(CFLAGS) $(INCLUDES) -o $(TARGET) $(OBJS) $(LFLAGS) $(LIBS) 

AMPL.o: AMPL.cpp 
    $(CC) $(CFLAGS) $(INCLUDES) -c AMPL.cpp 

all: $(TARGET) 

clean: 
    rm -f $(OBJS) $(TARGET) 

私は、環境変数に必要なdllファイル(libampl1.2.2.dll)のパスを追加しました。しかし firstexample.ccで#include "stdafx.h"を追加

  • (これは、Win32コンソールアプリケーションである)

    Makefileを使用しない

    • :私は2回の小さな変更でのVisual Studio 2015上でコードをコンパイルして実行することができますよ私は問題が何であるかわからない

      src\AMPLTesting.o: In function `ZN4ampl8internal11deleteTupleERNS0_5TupleE': 
      C:/Local/AMPL/AMPL32/amplapi32/include/ampl/ep/tuple_ep.h:24: undefined reference to `_imp___ZN4ampl8internal24AMPL_Variant_DeleteArrayEPKNS0_7VariantE' 
      src\AMPLTesting.o: In function `ZN4ampl8internal12TupleBuilderC1Ej': 
      C:/Local/AMPL/AMPL32/amplapi32/include/ampl/ep/tuple_ep.h:35: undefined reference to `_imp___ZN4ampl8internal24AMPL_Variant_CreateArrayEjPNS0_16ErrorInformationE' 
      collect2.exe: error: ld returned 1 exit status 
      

      :私はEclipseで同じコードを実行すると、それは私に次のエラーを与えますか?私はMakefileにいくつかのコマンドラインオプションがないか、特定のライブラリを追加していませんか?これで私を助けてください。

  • 答えて

    1

    C++ APIのベータ版は、現時点でWindows上のMSVCのみをサポートしています。将来のリリースでは、他のコンパイラのサポートが追加される予定です。

    +1

    ありがとうございました。 –

    関連する問題