jeudi 19 novembre 2020

Compile libcmaes with mingw

I'm trying to make a windows .exe file with Ubuntu 20.04.1 (VM on Windows host).

The source code includes libcmaes, so I can compile the follwing code with sudo x86_64-w64-mingw32-g++ -fopenmp -I/usr/include/eigen3 -I/usr/include/libcmaes -L/usr/lib -std=c++11 -o output.exe source.cpp -lcmaes and the generated files worked fine on ubuntu. But I couldn't compile it when g++ is replaced x86_64-w64-mingw32-g++ and terminal returned the error.

I commented out a little bit from the libcmaes sample code and found that it is probably not linked. Here is the code and the error content.

Code

#include <iostream>
#include <cmaes.h>
using namespace libcmaes;

FitFunc object = [](const double *x, const int N)
{
  double val = 0;
  for (int i=0;i<N;i++)
    val += x[i];
  return val;
};

int main()
{
  int dim = 10; // problem dimensions.
  std::vector<double> x0(dim,20.0);
  double sigma = 0.1;
  CMAParameters <> cmaparams(x0,sigma);
  //cmaparams.set_algo(BIPOP_CMAES);
  //CMASolutions cmasols = cmaes<>(object,cmaparams);
  //std::cout << "best solution: " << cmasols << std::endl;
  //std::cout << "optimization took " << cmasols.elapsed_time() / 1000.0 << " seconds\n";
  //return cmasols.run_status();
  return 0;
}

Result

/usr/bin/x86_64-w64-mingw32-ld: /tmp/cc67KYiT.o:finish.cpp:(.text+0x146): undefined reference to `libcmaes::CMAParameters<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> >::CMAParameters(std::vector<double, std::allocator<double> > const&, double const&, int const&, unsigned long long const&, libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> const&)'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/cc67KYiT.o:finish.cpp:(.text+0x166): undefined reference to `libcmaes::CMAParameters<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> >::~CMAParameters()'
collect2: error: ld returned 1 exit status

Please tell me what I should do.

Aucun commentaire:

Enregistrer un commentaire