ページ 11

fedoraでのcairommのクロスコンパイルについて

Posted: 2011年7月23日(土) 21:32
by chibago
boostに関しても同様な質問をさせていただきましたが(hikl様ありがとうございました)
Linux環境で動いているプログラムをwindowsで動かすためにfedoraのmingwでクロスコンパイル
を試みて居ります。現在はcairommがコンパイルできずに困って居ります。(Linuxのネイティブでは
問題ありません。)

同様の件で解決したboostからの推測では、どうやらmingw環境自体の完成度が低いと思われ、
どのようなものが通るか(実績があるか)ご周知いただければ非常に助かります。

おそらくどのようなものでも同じ結果となると推測されますが、
cairommのexampleをテストケース(test1.cpp)としてコンパイルを試みて居ります。
具体的には以下のようなものです。

コード:

#include <string>
#include <iostream>
#include <cairommconfig.h>
#include <cairomm/context.h>
#include <cairomm/surface.h>

#include <cmath>

int main()
{
    Cairo::RefPtr<Cairo::ImageSurface> surface =
        Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);

    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

    cr->save(); // save the state of the context
    cr->set_source_rgb(0.86, 0.85, 0.47);
    cr->paint(); // fill image with the color
    cr->restore(); // color is back to black now

    cr->save();
    // draw a border around the image
    cr->set_line_width(20.0); // make the line wider
    cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
    cr->stroke();

    cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
    // draw a circle in the center of the image
    cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,             surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
    cr->stroke();

    // draw a diagonal line
    cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
    cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);
    cr->stroke();
    cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

    std::string filename = "image.png";
    surface->write_to_png(filename);

    std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

    std::cout << "You must compile cairo with PNG support for this example to work."
        << std::endl;

#endif
}
コンパイルコマンドは以下のとおりです。
i686-pc-mingw32-g++ `mingw32-pkg-config cairomm-1.0 --cflags` `mingw32-pkg-config cairomm-1.0 --libs` test1.cpp -o out_win1.exe

この際に、やはりundefined referenceというエラーが出ます。
/tmp/cctjbzcS.o:test1.cpp:(.text+0x6e): undefined reference to `Cairo::ImageSurface::create(Cairo::Format, int, int)'
/tmp/cctjbzcS.o:test1.cpp:(.text+0xa3): undefined reference to `Cairo::Context::create(Cairo::RefPtr<Cairo::Surface> const&)'
/tmp/cctjbzcS.o:test1.cpp:(.text+0xcb): undefined reference to `Cairo::Context::save()'
/tmp/cctjbzcS.o:test1.cpp:(.text+0xfc): undefined reference to `Cairo::Context::set_source_rgb(double, double, double)'
/tmp/cctjbzcS.o:test1.cpp:(.text+0x10f): undefined reference to `Cairo::Context::paint()'
/tmp/cctjbzcS.o:test1.cpp:(.text+0x122): undefined reference to `Cairo::Context::restore()'
/tmp/cctjbzcS.o:test1.cpp:(.text+0x135): undefined reference to `Cairo::Context::save()'

pkg-configで展開されるパス等もとくにおかしな点がありません。
もし、cairommをmingw上で使えている方がいらっしゃれば
アドバイスをいただけると助かります。

(今後はgtkmmの使用も予定しておりますが、有益な関連情報
がございましたら合わせてお知らせいただければ幸です。)

Re: fedoraでのcairommのクロスコンパイルについて

Posted: 2011年7月23日(土) 23:47
by chibago
追加で記載いたします。
gtkmmに関してはどうなのかと思いhello worldを表示させるだけの
プログラム
http://www.hakodate-ct.ac.jp/~tokai/tok ... gin/p2.htm
を試しにコンパイルしてみました。

結果としては、同様に、undefined referenceのエラーが多数出て居ります。
現時点ではmingwもしくはmingwを用いたクロスコンパイルにおける
gtkmm,cairommなどのコンパイルは実用的ではないのかもしれません。

もし、コンパイルに成功した方がいらっしゃりましたら、
アドバイスいただけると助かります。

Re: fedoraでのcairommのクロスコンパイルについて

Posted: 2011年7月24日(日) 01:39
by chibago
解決出来ました。

i686-pc-mingw32-g++ `mingw32-pkg-config cairomm-1.0 --cflags` `mingw32-pkg-config cairomm-1.0 --libs` test1.cpp -o out_win1.exe

i686-pc-mingw32-g++ test1.cpp `mingw32-pkg-config cairomm-1.0 --cflags` `mingw32-pkg-config cairomm-1.0 --libs` -o out_win1.exe
としたらとおりました。

pkg-configで展開された文字列が悪さをしているか、mingw32-g++が特殊な挙動を示すのか
は分かりませんが、linuxネイティブでは通る作法が通用しないようです。