Undefined reference to (error) in C++ Eclipse but working in Visual Studio 2015 -


i trying integrate ampl c/c++ using ampl-api on windows-7 in eclipse mars 2.0. created makefile project in eclipse uses mingw cc compile firstexample code given in example directory.

firstexample.cpp:

#include <iostream> #include "ampl/ampl.h"  using namespace std;      int main() {         ampl::ampl ampl;          // read model , data files.         std::string modeldirectory = "models";         ampl.read(modeldirectory + "/diet/diet.mod");         ampl.readdata(modeldirectory + "/diet/diet.dat");          // solve         ampl.solve();          // objective entity ampl name         ampl::objective totalcost = ampl.getobjective("total_cost");         // print         std::cout << "objective is: " << totalcost.value() << std::endl;         // objective entity ampl name         ampl::objective totalcost = ampl.getobjective("total_cost");         // print         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 , ham." << std::endl;          // resolve , display objective         ampl.solve();         std::cout << "new objective value: " << totalcost.value() << std::endl;          // reassign data - instances         ampl::arg elements[8]{ 3, 5, 5, 6, 1, 2, 5.01, 4.55 };         cost.setvalues(elements);          std::cout << "updated costs." << std::endl;          // resolve , display objective         ampl.solve();         std::cout << "new objective value: " << totalcost.value() << std::endl;          // values of variable buy in dataframe object         variable buy = ampl.getvariable("buy");         ampl::dataframe df;         df = buy.getvalues();         // print them         df.print();         ampl::dataframe df2;         // values of expression dataframe object         df2 = ampl.getdata("{j in food} 100*buy[j]/buy[j].ub");         // print them         df2.print(); } 

following 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) 

i have added path of required dll files (libampl1.2.2.dll) environment variables. able compile , execute code on visual studio 2015 2 minor changes:

  • without using makefile (it win32 console application)
  • adding #include "stdafx.h" in firstexample.cc

however when execute same code in eclipse, gives me following error:

src\ampltesting.o: in function `zn4ampl8internal11deletetupleerns0_5tuplee': c:/local/ampl/ampl32/amplapi32/include/ampl/ep/tuple_ep.h:24: undefined reference `_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 `_imp___zn4ampl8internal24ampl_variant_createarrayejpns0_16errorinformatione' collect2.exe: error: ld returned 1 exit status 

i not sure problem? missing command line option in makefile or not adding specific library? please me this.

the beta version of c++ api supports msvc on windows @ moment. support other compilers added in future releases.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo