Hi,
I’m a beginner in OpenMesh so this question may seem to be funny. I’ve successfully installed OpenMesh using homebrew. But when I tried to run a simple testing program in CLion, things went wrong. Messages are like this:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/felix/Desktop/Learning/FillHole/FillHole/cmake-build-debug --target FillHole -- -j 4
Scanning dependencies of target FillHole
[ 50%] Building CXX object CMakeFiles/FillHole.dir/main.cpp.o
[100%] Linking CXX executable FillHole
Undefined symbols for architecture x86_64:
"OpenMesh::PolyConnectivity::add_face(std::vector<OpenMesh::VertexHandle, std::allocator<OpenMesh::VertexHandle> > const&)", referenced from:
_main in main.cpp.o
"OpenMesh::IO::_IOManager_::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, OpenMesh::IO::BaseExporter&, OpenMesh::IO::Options, long)", referenced from:
bool OpenMesh::IO::write_mesh<OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraits> >(OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraits> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, OpenMesh::IO::Options, long) in main.cpp.o
"OpenMesh::BaseProperty::stats(std::basic_ostream<char, std::char_traits<char> >&) const", referenced from:
vtable for OpenMesh::PropertyT<OpenMesh::DefaultTraits::EdgeT<OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::ITraits, OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::Refs> > in main.cpp.o
vtable for OpenMesh::PropertyT<OpenMesh::DefaultTraits::HalfedgeT<OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::ITraits, OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::Refs> > in main.cpp.o
vtable for OpenMesh::PropertyT<OpenMesh::DefaultTraits::FaceT<OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::ITraits, OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::Refs> > in main.cpp.o
vtable for OpenMesh::PropertyT<OpenMesh::DefaultTraits::VertexT<OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::ITraits, OpenMesh::FinalMeshItemsT<OpenMesh::DefaultTraits, false>::Refs> > in main.cpp.o
vtable for OpenMesh::PropertyT<OpenMesh::VectorT<float, 3> > in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [FillHole] Error 1
make[2]: *** [CMakeFiles/FillHole.dir/all] Error 2
make[1]: *** [CMakeFiles/FillHole.dir/rule] Error 2
make: *** [FillHole] Error 2
I think I’ve written my CMakeLists.txt correctly, so how can this happen? Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(FillHole)
set(CMAKE_CXX_STANDARD 11)
set(OpenMesh_FILE /usr/local/Cellar/open-mesh/7.1)
INCLUDE_DIRECTORIES(${OpenMesh_FILE}/include)
link_directories(${OpenMesh_FILE}/lib)
add_executable(FillHole main.cpp)
target_link_libraries(FillHole libOpenMeshCore.7.1.dylib libOpenMeshTools.7.1.dylib)
And here is my program:
#include <iostream>
// -------------------- OpenMesh
#include<unistd.h>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
// ----------------------------------------------------------------------------
typedef OpenMesh::PolyMesh_ArrayKernelT<> MyMesh;
// ----------------------------------------------------------------------------
// Build a simple cube and write it to std::cout
int main()
{
MyMesh mesh;
// generate vertices
MyMesh::VertexHandle vhandle[8];
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1, 1));
vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1, 1));
vhandle[2] = mesh.add_vertex(MyMesh::Point( 1, 1, 1));
vhandle[3] = mesh.add_vertex(MyMesh::Point(-1, 1, 1));
vhandle[4] = mesh.add_vertex(MyMesh::Point(-1, -1, -1));
vhandle[5] = mesh.add_vertex(MyMesh::Point( 1, -1, -1));
vhandle[6] = mesh.add_vertex(MyMesh::Point( 1, 1, -1));
vhandle[7] = mesh.add_vertex(MyMesh::Point(-1, 1, -1));
// generate (quadrilateral) faces
std::vector<MyMesh::VertexHandle> face_vhandles;
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[6]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[7]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[4]);
mesh.add_face(face_vhandles);
OpenMesh::IO::write_mesh(mesh, "output.off");
// write mesh to output.obj
try
{
if ( !OpenMesh::IO::write_mesh(mesh, "output.off") )
{
std::cerr << "Cannot write mesh to file 'output.off'" << std::endl;
return 1;
}
}
catch( std::exception& x )
{
std::cerr << x.what() << std::endl;
return 1;
}
std::cout << "nice"<<std::endl;
return 0;
}
Can you help me find where the problem is? Thank you very much!