我是C ++的新手,几周前我刚刚在Windows PC上安装了Ubuntu。
我必须使用一个称为Voxelyze的静态库(我从Here下载了该库。您可以在其中查看include,lib和makefile的位置)。而且我正在尝试编译示例代码(我将其命名为testeo.cpp)。
我的testeo.cpp路径是:c / Users / Familia / Desktop / MEMORIA / F / galib247 / galib247 / examples
voxelyze库路径为: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;
}
此代码仅将三个体素连续放置,在第三个体素中施加向下的力,然后模拟其行为,并针对每个时间步模拟显示其位移。
好吧,现在,在我的ubuntu命令中(执行sudo apt-get -y更新,sudo apt-get -y升级和sudo apt-get install build-essential之后),我首先进入voxelyze目录,然后执行“先制作”,然后再制作”,这样就可以制作出所有需要制作的东西:
$ cd /mnt/c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples/Voxelyze-master
$ make clean
$ make
到目前为止一切顺利。
然后,通过简单地执行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世界中我还很陌生,但是无论您需要什么其他信息来解决这个难题,我都会尽力提供帮助。
谢谢。