2016-06-02 2 views
1

Eclipse Mars 2.0의 Windows-7에서 AMPL-API을 사용하여 C/C++에 AMPL을 C/C++와 통합하려고합니다. Eclipse에서 MinGW CC를 사용하여 예제 디렉토리에있는 첫 번째 코드를 컴파일하는 Makefile 프로젝트를 만들었습니다. C++ Eclipse에서 정의되지 않은 참조 (Visual Studio에서 작동 중임) 2015

#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.cpp:

. 내가 컴파일하고 두 개의 작은 변화와 비주얼 스튜디오 2015에서 코드를 실행할 수 있어요 : Makefile을 사용하지 않고

그러나 firstexample.cc에 #include "stdafx.h" 추가

  • (그것은 Win32 콘솔 응용 프로그램입니다) 나는 문제가 무엇 확실하지 않다

    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 
    

    : 이클립스에서 동일한 코드를 실행할 때, 그것은 나에게 다음과 같은 오류를 준다? Makefile에 명령 줄 옵션이 없거나 특정 라이브러리를 추가하지 않았습니까? 이걸 도와주세요.

  • 답변

    1

    C++ API의 베타 버전은 현재 Windows에서 MSVC 만 지원합니다. 다른 컴파일러에 대한 지원은 향후 릴리스에서 추가 될 예정입니다.

    +1

    업데이트를위한 감사 바이타트 :) –