我正在使用
Lapack
在我的C++代码中。我很困惑如何正确链接到图书馆。下面是一个小示例,对应于我从Lapack调用函数的代码:
#include <iostream>
namespace lapack { extern "C" {
void ilaver(int* major, int* minor, int* patch); } }
int main()
{
int major = 0;
int minor = 0;
int patch = 0;
lapack::ilaver(&major, &minor, &patch);
std::cout << major << "." << minor << "." << patch << std::endl;
return 0;
}
> g++ ilaver.cpp -o ilaver -L /softs/lapack/3.7.1/64/gcc/4.8.5/lib64 -l lapack
/tmp/ccHvDCAh.o: In function `main':
ilaver.cpp:(.text+0x33): undefined reference to `ilaver'
collect2: error: ld returned 1 exit status
我知道这是一个
名字改编
问题如果我更改代码,在函数名的末尾添加下划线,它将使用GCC正确编译:
#include <iostream>
namespace lapack { extern "C" {
void ilaver_(int* major, int* minor, int* patch); } }
int main()
{
int major = 0;
int minor = 0;
int patch = 0;
lapack::ilaver_(&major, &minor, &patch);
std::cout << major << "." << minor << "." << patch << std::endl;
return 0;
}
但它不能在Windows下用英特尔的编译器编译。在那里,破损是不同的,我必须把它改成
lapack::ILAVER
我的代码必须在几种配置(Linux/Mac/Windows)下用几种编译器(GCC、Intel、MSVC)编译。我怎样才能更通用,并确保它将在一个大型编译器面板下编译?