编译和链接体素分析库时出现问题 我在C++中比较新,我几周前刚刚在Windows PC上安装了Ubuntu。

编译和链接体素分析库时出现问题 我在C++中比较新,我几周前刚刚在Windows PC上安装了Ubuntu。,c++,linux,ubuntu,C++,Linux,Ubuntu,我必须使用一个名为Voxelyze的静态库(我从那里下载的,你可以看到include、libs和makefile在哪里)。我正在尝试编译一个示例代码(我将其命名为testeo.cpp) 我的testeo.cpp路径是:c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples 体素分析库路径为:c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples/voxelyze m

我必须使用一个名为Voxelyze的静态库(我从那里下载的,你可以看到include、libs和makefile在哪里)。我正在尝试编译一个示例代码(我将其命名为testeo.cpp)

我的testeo.cpp路径是:c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples

体素分析库路径为:c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples/voxelyze master

代码如下:

#include "Voxelyze.h"
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
  cout << "Testing voxelyze library\n";
  CVoxelyze Vx(0.005); //5mm voxels
  CVX_Material* pMaterial = Vx.addMaterial(1000000, 1000); //A material with stiffness E=1MPa and density 1000Kg/m^3
  CVX_Voxel* Voxel1 = Vx.setVoxel(pMaterial, 0, 0, 0); //Voxel at index x=0, y=0, z=0
  CVX_Voxel* Voxel2 = Vx.setVoxel(pMaterial, 1, 0, 0);
  CVX_Voxel* Voxel3 = Vx.setVoxel(pMaterial, 2, 0, 0); //Beam extends in the +X direction
  Voxel1->external()->setFixedAll(); //Fixes all 6 degrees of freedom with an external condition on Voxel 1
  Voxel3->external()->setForce(0, 0, -1); //pulls Voxel 3 downward with 1 Newton of force.

  for (int i=0; i<100; i++){
    Vx.doTimeStep(); //simulate 100 timesteps.
    cout << "Current position: " << (float)Voxel3->position().z << "\n";
  }

  return 0;
}
到目前为止还不错

然后,通过简单地执行cd.返回testeo.cpp路径。。并且,使用GCC,我尝试以这种方式编译testeo.cpp:

$ cd..
$ g++ -Wall -o testeo testeo.cpp -I./Voxelyze-master/include -L./Voxelyze-master/lib/ -lvoxelyze.0.9
但我收到以下错误消息:

testeo.cpp: In function ‘int main()’:
testeo.cpp:15:14: warning: unused variable ‘Voxel2’ [-Wunused-variable]
   15 |   CVX_Voxel* Voxel2 = Vx.setVoxel(pMaterial, 1, 0, 0);
      |              ^~~~~~
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::CVX_LinearSolver(CVoxelyze*)':
VX_LinearSolver.cpp:(.text+0x123): undefined reference to `pardisoinit'
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::solve()':
VX_LinearSolver.cpp:(.text+0x2a13): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2b17): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2c26): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2e30): undefined reference to `pardiso'
collect2: error: ld returned 1 exit status
我不太关心警告消息,但关心“未定义的错误引用”

我认为这是一个内部库错误,(或者我在我的链接IDK中做错了什么),因为它在抱怨一些“LinearSolver”类函数和“pardiso”之类的东西。。。但是我没有在testeo.cpp代码中使用它们(至少不是直接使用)

嗯,我不知道如何使这件事的工作,我的工程学位是线在这里哈哈哈

我希望你能在这里帮助我,我会非常感谢你。我对C++-Linux这个世界相当陌生,但无论您需要什么额外的信息来解开这个谜团,我都会尽力帮助您


谢谢。

静态库只不过是对象文件的存档,使用静态库类似于列出对象文件本身。这意味着静态库所依赖的任何附加库也需要链接。所以你也需要链接到
体素分析
库依赖项。嗨,程序员,首先,非常感谢你的回答。但是,如何才能看到体素分析所依赖的库?我必须搜索每个文件或某个特定位置吗?好的@Someprogrammerdude,我正在阅读线性解算器头文件,我发现:
#ifdef PARDISO_5#ifdef_WIN32#pragma comment(lib,“libpardiso500-WIN-X86-64.lib”)//链接到PARDISO库#endif
,因此,我必须链接到该库。。。我必须先下载、安装或做些什么吗?阅读链接,很简单。我读了很多关于链接的书,但现在我有很多关于pardiso版本的问题。我将在另一个线程中跟踪此内容:
testeo.cpp: In function ‘int main()’:
testeo.cpp:15:14: warning: unused variable ‘Voxel2’ [-Wunused-variable]
   15 |   CVX_Voxel* Voxel2 = Vx.setVoxel(pMaterial, 1, 0, 0);
      |              ^~~~~~
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::CVX_LinearSolver(CVoxelyze*)':
VX_LinearSolver.cpp:(.text+0x123): undefined reference to `pardisoinit'
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::solve()':
VX_LinearSolver.cpp:(.text+0x2a13): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2b17): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2c26): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2e30): undefined reference to `pardiso'
collect2: error: ld returned 1 exit status