写入gsv文字时,AntiGrain Geometry程序中出现未定义的参考错误

时间:2019-03-03 17:51:21

标签: c++

我正在尝试使用AntiGrain Geometry库中的gsv_text将文本写入缓冲区,并且遇到未定义的引用错误:

/tmp/ccmaHChV.o: In function `text(agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip<agg::ras_conv_int> >&, agg::scanline_p8&, agg::renderer_scanline_aa_solid<agg::renderer_base<agg::pixfmt_alpha_blend_rgb<agg::blender_rgb<agg::rgba8, agg::order_bgr>, agg::row_accessor<unsigned char> > > >&, double, double, char const*)':
eg2.cpp:(.text+0x231): undefined reference to `agg::gsv_text::gsv_text()'
eg2.cpp:(.text+0x25a): undefined reference to `agg::gsv_text::size(double, double)'
eg2.cpp:(.text+0x273): undefined reference to `agg::gsv_text::text(char const*)'
eg2.cpp:(.text+0x2a4): undefined reference to `agg::gsv_text::start_point(double, double)'
/tmp/ccmaHChV.o: In function `agg::conv_adaptor_vcgen<agg::gsv_text, agg::vcgen_stroke, agg::null_markers>::conv_adaptor_vcgen(agg::gsv_text&)':
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEEC2ERS1_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEEC5ERS1_]+0x27): undefined reference to `agg::vcgen_stroke::vcgen_stroke()'
/tmp/ccmaHChV.o: In function `agg::conv_adaptor_vcgen<agg::gsv_text, agg::vcgen_stroke, agg::null_markers>::rewind(unsigned int)':
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6rewindEj[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6rewindEj]+0x1f): undefined reference to `agg::gsv_text::rewind(unsigned int)'
/tmp/ccmaHChV.o: In function `agg::conv_adaptor_vcgen<agg::gsv_text, agg::vcgen_stroke, agg::null_markers>::vertex(double*, double*)':
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x7f): undefined reference to `agg::gsv_text::vertex(double*, double*)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0xc8): undefined reference to `agg::vcgen_stroke::remove_all()'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x101): undefined reference to `agg::vcgen_stroke::add_vertex(double, double, unsigned int)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x157): undefined reference to `agg::gsv_text::vertex(double*, double*)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x1e5): undefined reference to `agg::vcgen_stroke::add_vertex(double, double, unsigned int)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x27f): undefined reference to `agg::vcgen_stroke::add_vertex(double, double, unsigned int)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x294): undefined reference to `agg::vcgen_stroke::rewind(unsigned int)'
eg2.cpp:(.text._ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_[_ZN3agg18conv_adaptor_vcgenINS_8gsv_textENS_12vcgen_strokeENS_12null_markersEE6vertexEPdS5_]+0x2bd): undefined reference to `agg::vcgen_stroke::vertex(double*, double*)'
collect2: error: ld returned 1 exit status

代码如下: eg2.cpp

#include "eg2.h"
#include<stdio.h>
#include<string.h>
#include <math.h>
#include "../agg-2.5/include/agg_basics.h"
#include "../agg-2.5/include/agg_rendering_buffer.h"
#include "../agg-2.5/include/agg_rasterizer_scanline_aa.h"
#include "../agg-2.5/include/agg_rasterizer_outline.h"
#include "../agg-2.5/include/agg_scanline_p.h"
#include "../agg-2.5/include/agg_scanline_bin.h"
#include "../agg-2.5/include/agg_renderer_scanline.h"
#include "../agg-2.5/include/agg_renderer_primitives.h"
#include "../agg-2.5/include/agg_pixfmt_rgb.h"
#include "../agg-2.5/include/agg_path_storage.h"
#include "../agg-2.5/include/platform/agg_platform_support.h"
#include "../agg-2.5/include/agg_conv_transform.h"
#include "../agg-2.5/include/agg_conv_stroke.h"
#include "../agg-2.5/include/agg_gsv_text.h"
#include "../agg-2.5/include/agg_pattern_filters_rgba.h"
#include "../agg-2.5/include/agg_renderer_outline_aa.h"
#include "../agg-2.5/include/agg_renderer_outline_image.h"

typedef agg::pixfmt_bgr24 pixfmt;
enum flip_y_e { flip_y = true };

enum{
  frame_width = 500,
  frame_height = 330
};

bool write_ppm(const unsigned char* buf,
                unsigned width,
                unsigned height,
                const char* file_name)
                {
                  FILE* fd = fopen(file_name, "wb");
                  if(fd){
                    fprintf(fd, "P6 %d %d 255 ", width, height);
                    fwrite(buf, 1, width*height*3, fd);
                    fclose(fd);
                    return true;
                  }
                  return false;
                }

void draw_black_frame(agg::rendering_buffer& rbuf){
  unsigned i;
  for(i = 0; i<rbuf.height();i++){
    unsigned char* p = rbuf.row_ptr(i);
    *p++ = 0; *p++ = 0; *p++ = 0;
    p += (rbuf.width() - 2)*3;
    *p++ = 0; *p++ = 0; *p++ = 0;
  }
  memset(rbuf.row_ptr(0), 0, rbuf.width()*3);
  memset(rbuf.row_ptr(rbuf.height()-1), 0, rbuf.width()*3);
}

typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_aa;
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_bin;
typedef agg::rasterizer_scanline_aa<> rasterizer_scanline;
typedef agg::scanline_p8 scanline;

void text(rasterizer_scanline& ras,
          scanline& sl,
          renderer_aa& ren,
          double x, double y, const char* txt)
{
    agg::gsv_text t;
    t.size(8);
    t.text(txt);
    t.start_point(x, y);
    agg::conv_stroke<agg::gsv_text> stroke(t);
    stroke.width(0.7);
    ras.add_path(stroke);
    ren.color(agg::rgba(0,0,0));
    agg::render_scanlines(ras, sl, ren);
}

int main() {

  double m_x[3];
  double m_y[3];
  m_x[0] = 100 + 120; m_y[0] = 60;
  m_x[1] = 369 + 120; m_y[1] = 170;
  m_x[2] = 143 + 120; m_y[2] = 310;

  agg::rasterizer_scanline_aa<> m_ras;
  agg::scanline_p8              m_sl_p8;
  agg::scanline_bin             m_sl_bin;

  unsigned char* buffer = new unsigned char[frame_width*frame_height*3];

  memset(buffer, 255, frame_width*frame_height*3);

  agg::rendering_buffer rbuf(buffer,
                            frame_width,
                            frame_height,
                            frame_width*3);

  pixfmt pixf(rbuf);
  renderer_base rb(pixf);
  renderer_aa ren_aa(rb);

  agg::path_storage path;

  path.move_to(m_x[0], m_y[0]);
  path.line_to(m_x[1], m_y[1]);
  path.line_to(m_x[2], m_y[2]);
  path.close_polygon();

  ren_aa.color(agg::rgba(0.7, 0.5, 0.1, 1.0));

  m_ras.gamma(agg::gamma_power(1.0 * 2.0));
  m_ras.add_path(path);
  agg::render_scanlines(m_ras, m_sl_p8, ren_aa);

  text(m_ras, m_sl_p8, ren_aa, 50, rbuf.height()/2+50, "Hello");

  write_ppm(buffer, frame_width, frame_height, "agg_test.ppm");

  delete [] buffer;
  return 0;
}

eg2.h

#ifdef __cplusplus
extern "C" {
#endif
  void start_func(void);
#ifdef __cplusplus
}
#endif

此错误的确切含义是什么?我该如何纠正?这是否意味着我需要使用new关键字创建gsv_text对象?我尝试过,但是没有用。

0 个答案:

没有答案