需要使用g++编译vcglib代码的帮助

Need help compiling vcglib code with g++

本文关键字:vcglib 代码 帮助 编译 g++      更新时间:2023-10-16

我正在学习如何使用库vcglib(http://vcg.sourceforge.net/index.php/Main_Page)但我在编译任何东西的时候都是最困难的。现在,我正在尝试编译trimesh_definition.cpp,这只是vcglib附带的一个基本示例,它应该展示如何启动和运行一切。

这是我试图混淆的代码:

1  #include <vector>
2 
3  #include <vcg/simplex/vertex/base.h>
4  #include <vcg/simplex/vertex/component.h>
5  #include <vcg/simplex/face/base.h>
6  #include <vcg/simplex/face/component.h>
7 
8  #include <vcg/complex/complex.h>
9 
10 class MyEdge;
11 class MyFace;
12 
13 class MyVertex: public vcg::VertexSimp2<MyVertex,MyEdge,MyFace, vcg::vert::Coord3d, vcg::vert::Normal3f>{};
14 class MyFace: public vcg::FaceSimp2<MyVertex,MyEdge,MyFace, vcg::face::VertexRef>{};
15 
16 class MyMesh: public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
17 
18 int main()
19 {
20    MyMesh m;
21    return 0;
22 }

我用以下命令组合代码:

g++ -I ../../../vcglib trimesh_definition.cpp -o trimesh_def

我得到以下错误:

trimesh_definition.cpp:13:40: error: expected template-name before ‘<’ token
trimesh_definition.cpp:13:40: error: expected ‘{’ before ‘<’ token
trimesh_definition.cpp:13:40: error: expected unqualified-id before ‘<’ token
trimesh_definition.cpp:14:36: error: expected template-name before ‘<’ token
trimesh_definition.cpp:14:36: error: expected ‘{’ before ‘<’ token
trimesh_definition.cpp:14:36: error: expected unqualified-id before ‘<’ token
In file included from trimesh_definition.cpp:8:0:
/home/martin/Programming/Graphics/libraries/vcglib/vcg/complex/complex.h: In instantiation of ‘vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> >’:
trimesh_definition.cpp:16:86:   instantiated from here
(... followed by many more screenfulls of template info)

我对模板了解不多,所以我不知道问题出在哪里,也不知道该如何解决。这是从我上面链接的vcglib网站上直接下载的代码,我没有修改任何代码,所以我很惊讶它没有编译。

看起来他们给出的大多数例子都是针对windows电脑和视觉工作室的。我正在运行arch-linux,并使用g++编译它。问题可能是两个编译器之间的差异吗?

我真的很失落,任何帮助都将不胜感激。

VertexSimp2(以及1和3)是旧版本vcg中使用的类。搜索您的Lib,您将找不到class VertexSimp2的定义。

这正是编译器所说的,vcg::VertexSimp2应该是一个类型,但事实并非如此。

教程为您提供了实际的解决方案:

class MyUsedTypes: public vcg::UsedTypes< vcg::Use<MyVertex>::AsVertexType>,
                                          vcg::Use<MyFace>::AsFaceType>  

class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3d, vcg::vertex::Normal3f> {};
class MyFace : public vcg::Face<MyUsedTypes, vcg::face::VertexRef> {};
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};