【问题标题】:How to compile using LoopTools in C++如何在 C++ 中使用 LoopTools 进行编译
【发布时间】:2022-08-24 01:17:01
【问题描述】:

我正在尝试使用以下称为 LoopTools 的 C++ 工具:http://www.feynarts.de/looptools/

它基本上给出了一些积分的数值。

manual 说,为了使用它,我必须:

就像在 Fortran 案例中一样,它节省了大量的输入来指定 LoopTools 的位置 一次在环境变量中。例如,在 tcsh 中,使用 setenv LT $HOME/LoopTools/(hosttype) 然后使用以下命令编译使用 LoopTools 的程序:$LT/bin/fcc -I$LT/include (source files) -L$LT/lib -looptools

我尝试使用他们提供的示例代码来执行此操作:

#include <iostream>
#include \"clooptools.h\"
int main() {
ltini();
cout << B0(1000., 50., 80.) << endl;
ltexi();
}

我将此代码保存为 \"example.cpp\" 并尝试使用他们所说的进行编译,即:

g++ example.cpp $LT/bin/fcc -I$LT/include -L$LT/lib -looptools

但我得到以下

.../LoopTools-2.16/x86_64-Linux/bin/fcc: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status

我应该怎么办?

  • 你应该做的是弄清楚你是否为你的操作系统下载了正确的二进制文件。您是否尝试在 64 位 Linux 发行版上运行它?或许您还应该重新考虑从 Internet 下载随机二进制文件,并首先在您的计算机上运行它们。
  • 他们希望您使用$LT/bin/fcc 作为编译器,而不是g++
  • 好的,我发现它实际上应该是$LT/bin/fcc -I$LT/include -L$LT/lib64 -looptools。 @HolyBlackCat 现在我尝试将其编译为$LT/bin/fcc example.cpp -I$LT/include -L$LT/lib64 -looptools,现在我收到以下错误:/usr/bin/ld: /tmp/ccsFqRan.o: in function _GLOBAL__sub_I_first_try.cpp\': /usr/include/c++/11/iostream:74: undefined reference to std::ios_base::Init::Init()\' /usr/bin/ld: /tmp/ccsFqRan.o: in function __static_initialization_and_destruction_0\': /usr/include/c++/11/iostream:74: undefined reference to std::ios_base::Init::~Init()\'
  • @SamVarshavchik 我想我确实下载了正确的,特别是因为只有一个链接可供下载。这个工具也可用于 Mathematica,我用过它没有问题,但我现在正试图在 C++ 上使用它
  • 如果fcc 相当于gcc,那么它将尝试像C 程序而不是C++ 程序一样编译它,并且不会链接&lt;iostream&gt; 使用的库。

标签: c++


【解决方案1】:

对我来说,它适用于以下更改(Ubuntu 20.04、x86_64、LoopTools-2.16)。

  1. 插入以下行,

    using namespace::std;
    

    到您的example.cpp,在使用cout/endl之前。

  2. $LT/bin/fcc 的第19 行,从cxx 变量中删除-stdlib=libstdc++ 编译器标志,这对于g++ 似乎无效:

    cxx="${REALCXX:-g++ -O3 -g -fomit-frame-pointer -ffast-math -fPIC -Wall -m64}"
    
  3. $LT/bin/fcc 的第 53 行,添加 .cpp 作为 C++ 文件后缀:

      *.cc|*.cpp)
    

    否则,您需要将示例文件重命名为 example.cc

  4. 如您所见,该库安装在 64 位 Linux 上的 $LT/lib64 中。编译程序

    $LT/bin/fcc -I$LT/include example.cpp -L$LT/lib64 -looptools
    

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多