cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Error compile vtable in Debug with GCC 15.2.0

Open Joraslav opened this issue 3 months ago • 5 comments

Issue Details

Project build error during the linking stage. An error related to vtable. I don't use a virtual table in my project

Source Code

IO.hpp:

#pragma once

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <string>

namespace io {

class IO {
 public:
    using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
    using Point = Kernel::Point_3;
    using Mesh = CGAL::Surface_mesh<Point>;

    static Mesh Read(const std::string& filename);

    static void Write(const std::string& filename, const Mesh& mesh);
};

}  // namespace io

IO.cpp:

#include "IO.hpp"

#include <CGAL/IO/STL.h>

#include <array>
#include <fstream>
#include <stdexcept>
#include <vector>

namespace io {

using std::string_literals::operator""s;

IO::Mesh IO::Read(const std::string& filename) {
    std::ifstream fin(filename, std::ios::binary);
    if (!fin) {
        throw std::runtime_error("Could not open file to read: "s + filename);
    }

    Mesh mesh;
    std::vector<Point> points;
    std::vector<std::array<size_t, 3>> triangles;
    if (!CGAL::IO::read_STL(fin, points, triangles)) {
        throw std::runtime_error("Error reading STL file: "s + filename);
    }

    std::vector<Mesh::Vertex_index> vertices;
    for (const Point& p : points) {
        vertices.push_back(mesh.add_vertex(p));
    }
    for (const auto& tri_array : triangles) {
        mesh.add_face(vertices[tri_array[0]], vertices[tri_array[1]], vertices[tri_array[2]]);
    }

    fin.close();
    return mesh;
}

void IO::Write(const std::string& filename, const Mesh& mesh) {
    std::ofstream fout(filename, std::ios::binary);
    if (!fout) {
        throw std::runtime_error("Could not open file to write: "s + filename);
    }

    if (!CGAL::IO::write_STL(fout, mesh)) {
        throw std::runtime_error("Error writing STL file: "s + filename);
    }

    fout.close();
}

}  // namespace io

main.cpp:

#include "IO.hpp"
#include <CGAL/Alpha_shape_3.h>
#include <CGAL/alpha_wrap_3.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/bbox.h>
#include <CGAL/Surface_mesh.h>

#include <array>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using std::string_literals::operator""s;

using namespace io;
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point = Kernel::Point_3;
using Mesh = CGAL::Surface_mesh<Point>;

const std::string INPUT_DIR = "../data/variation_models"s;
const std::string OUTPUT_DIR = "../out"s;

int main() {
    try {
        Mesh mesh = IO::Read(INPUT_DIR + "/Pump.stl"s);

        const double relative_alpha = 5.0;
        const double relative_offset = 6.0;

        CGAL::Bbox_3 bbox = CGAL::Polygon_mesh_processing::bbox(mesh);
        const double diag_length = std::sqrt(CGAL::square(bbox.xmax() - bbox.xmin()) +
                                             CGAL::square(bbox.ymax() - bbox.ymin()) +
                                             CGAL::square(bbox.zmax() - bbox.zmin()));

        const double alpha = diag_length / relative_alpha;
        const double offset = diag_length / relative_offset;

        Mesh wrap;
        CGAL::alpha_wrap_3(mesh, alpha, offset, wrap);

        IO::Write(OUTPUT_DIR + "/Pump_alpha_shape.stl"s, wrap);

    } catch (const std::exception& e) {
        std::cerr << e.what() << '\n';
    }

    return 0;
}

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Windows
  • Compiler: GCC 15.2.0 from MSYS2
  • Release or debug mode: DEBUG
  • Specific flags used (if any):
  • CGAL version: 6.0.1
  • Boost version: 1.89.0
  • Other libraries versions if used (Eigen, TBB, etc.):

Attached files

variation_models.zip

Joraslav avatar Sep 30 '25 11:09 Joraslav

Error:

[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.data+0x200): undefined reference to `typeinfo for CGAL::internal::Throw_at_output_exception'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL23Postcondition_exceptionC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_S6_iS6_[_ZN4CGAL23Postcondition_exceptionC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_S6_iS6_]+0x11d): undefined reference to `vtable for CGAL::Postcondition_exception'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL23Postcondition_exceptionD1Ev[_ZN4CGAL23Postcondition_exceptionD1Ev]+0xf): undefined reference to `vtable for CGAL::Postcondition_exception'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL18postcondition_failEPKcS1_iS1_[_ZN4CGAL18postcondition_failEPKcS1_iS1_]+0x1ad): undefined reference to `typeinfo for CGAL::Postcondition_exception'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL19Ref_counted_virtualC2Ev[_ZN4CGAL19Ref_counted_virtualC2Ev]+0xb): undefined reference to `vtable for CGAL::Ref_counted_virtual'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL19Ref_counted_virtualC2ERKS0_[_ZN4CGAL19Ref_counted_virtualC2ERKS0_]+0xf): undefined reference to `vtable for CGAL::Ref_counted_virtual'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZNK4CGAL19Ref_counted_virtual4typeEv[_ZNK4CGAL19Ref_counted_virtual4typeEv]+0xb): undefined reference to `.refptr._ZTIv'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL19Ref_counted_virtualD2Ev[_ZN4CGAL19Ref_counted_virtualD2Ev]+0xb): undefined reference to `vtable for CGAL::Ref_counted_virtual'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL19Ref_counted_virtualD1Ev[_ZN4CGAL19Ref_counted_virtualD1Ev]+0xb): undefined reference to `vtable for CGAL::Ref_counted_virtual'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZNSt9once_flag18_Prepare_executionD1Ev[_ZNSt9once_flag18_Prepare_executionD1Ev]+0xf): undefined reference to `.refptr.__emutls_v._ZSt15__once_callable'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZNSt9once_flag18_Prepare_executionD1Ev[_ZNSt9once_flag18_Prepare_executionD1Ev]+0x25): undefined reference to `.refptr.__emutls_v._ZSt11__once_call'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL21Triangulation_utils_33ccwEi[_ZN4CGAL21Triangulation_utils_33ccwEi]+0x73): undefined reference to `CGAL::Triangulation_utils_base_3<void>::ccw_map'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL21Triangulation_utils_32cwEi[_ZN4CGAL21Triangulation_utils_32cwEi]+0x73): undefined reference to `CGAL::Triangulation_utils_base_3<void>::cw_map'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL21Triangulation_utils_316next_around_edgeEii[_ZN4CGAL21Triangulation_utils_316next_around_edgeEii]+0xd8): undefined reference to `CGAL::Triangulation_utils_base_3<void>::tab_next_around_edge'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL21Triangulation_utils_319vertex_triple_indexEii[_ZN4CGAL21Triangulation_utils_319vertex_triple_indexEii]+0x95): undefined reference to `CGAL::Triangulation_utils_base_3<void>::tab_vertex_triple_index'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL3RepC2Ei[_ZN4CGAL3RepC2Ei]+0x12): undefined reference to `vtable for CGAL::Rep'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL3RepD2Ev[_ZN4CGAL3RepD2Ev]+0xb): undefined reference to `vtable for CGAL::Rep'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL3RepD1Ev[_ZN4CGAL3RepD1Ev]+0xb): undefined reference to `vtable for CGAL::Rep'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL18get_default_randomEv[_ZN4CGAL18get_default_randomEv]+0xb): undefined reference to `__emutls_v._ZGVZN4CGAL18get_default_randomEvE14default_random'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\DownScalerSTL.dir/objects.a(example.cpp.obj):example.cpp:(.text$_ZN4CGAL18get_default_randomEv[_ZN4CGAL18get_default_randomEv]+0x21): undefined reference to `__emutls_v._ZZN4CGAL18get_default_randomEvE14default_random'

And e.t.

Joraslav avatar Sep 30 '25 11:09 Joraslav

Hello, could you give more information about how exactly you compile your project?

mglisse avatar Oct 01 '25 07:10 mglisse

I can download my project in its entirety so you can check it out. My project is small

Joraslav avatar Oct 01 '25 17:10 Joraslav

What Marc is asking for are compilation flags and how you do compile. You are showing link errors while the library is header only.

sloriot avatar Oct 02 '25 06:10 sloriot

@Joraslav Is that project DownScalerSTL available somewhere on Github, so that we can check by ourself?

lrineau avatar Oct 06 '25 07:10 lrineau

Bump @Joraslav

MaelRL avatar Dec 11 '25 15:12 MaelRL