【发布时间】:2021-03-02 23:38:12
【问题描述】:
我正在尝试使用 Ubuntu 20.04.1(Windows 主机上的虚拟机)制作一个 windows .exe 文件。
源代码包含 libcmaes,因此我可以使用 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 编译以下代码,并且生成的文件在 ubuntu 上运行良好。
但是当g++被替换为x86_64-w64-mingw32-g++并且终端返回错误时,我无法编译它。
我从libcmaes示例代码中注释掉了一点,发现它可能没有链接。 这是代码和错误内容。
代码
#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;
}
结果
/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
请告诉我应该怎么做。
【问题讨论】:
-
我将每个文件从 /usr/lib/~ 复制到 /usr/x86_64-w64-mingw32/~ 并更改了命令
$ sudo x86_64-w64-mingw32-g++ -fopenmp -I/usr/x86_64-w64-mingw32/include/eigen3 -I/usr/x86_64-w64-mingw32/include/libcmaes -L/usr/x86_64-w64-mingw32/lib -static-libstdc++ -static-libgcc -std=c++11 -o finish.exe finish.cpp -lcmaes,但没有编译。
标签: c++ c++11 ubuntu mingw cross-compiling