在MathGL中运行程序

时间:2014-10-25 05:15:29

标签: mathgl

我正在尝试使用Mathgl中的FLTK运行其中一个示例。虽然基本程序编译时没有错误,但在编译FLTK_MathGL示例时,我似乎遇到了链接器错误。

这是我从构建日志中获得的错误部分。

C:\ mathgl-2.3 \ src \ libmgl.dll.a C:\ mathgl-2.3 \ widgets \ libmgl-fltk.a -mwindows obj \ Release \ main.o:main.cpp :(。text $ _ZN7mglFLTK3RunEv [__ ZN7mglFLTK3RunEv] + 0x1):未定义引用“_imp__mgl_fltk_run” obj \ Release \ main.o:main.cpp:(。text $ _ZN7mglFLTKC1EPFiP8mglGraphEPKc [__ ZN7mglFLTKC1EPFiP8mglGraphEPKc] + 0x39):未定义引用“_imp ___ ZTV7mglFLTK” c:/ codeblocks / mingw / bin /../ lib / gcc / mingw32 / 4.8.1 /../../../../ mingw32 / bin / ld.exe:obj \ Release \ main.o: “部分中的错误重定位地址0x39。text $ _ZN7mglFLTKC1EPFiP8mglGraphEPKc [__ ZN7mglFLTKC1EPFiP8mglGraphEPKc]' c:/ codeblocks / mingw / bin /../ lib / gcc / mingw32 / 4.8.1 /../../../../ mingw32 / bin / ld.exe:最终链接失败:操作无效 collect2.exe:错误:ld返回1退出状态 处理终止,状态为1(0分钟,3秒) 2个错误,0个警告(0分钟,3秒(s))

我不确定我还能做什么。我已粘贴下面的程序。

#define MGL_HAVE_FLTK
#include "mgl2/fltk.h"

//-----------------------------------------------------------------------------
#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h>
#else
#include <unistd.h>
#endif
void long_calculations()    // just delay which correspond to simulate calculations
{
#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__)
    Sleep(1000);
#else
    sleep(1);   // which can be very long
#endif
}
//-----------------------------------------------------------------------------
#if defined(PTHREAD_SAMPLE1)    // first variant of multi-threading usage of mglFLTK window
mglFLTK *gr=NULL;
void *calc(void *)
{
    mglPoint pnt;
    for(int i=0;i<10;i++)       // do calculation
    {
        long_calculations();    // which can be very long
        pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
        if(gr)
        {
            gr->Clf();          // make new drawing
            gr->Line(mglPoint(),pnt,"Ar2");
            char str[10] = "i=0";   str[2] = '0'+i;
            gr->Puts(mglPoint(),str);
            gr->Update();       // update window
        }
    }
    exit(0);
}
int main(int argc,char **argv)
{
    static pthread_t thr;
    pthread_create(&thr,0,calc,0);
    pthread_detach(thr);
    gr = new mglFLTK;
    gr->Run();  return 0;
}
#elif defined(PTHREAD_SAMPLE2)  // another variant of multi-threading usage of mglFLTK window. Work only if pthread was enabled for MathGL
mglPoint pnt;   // some global variable for changeable data
int main(int argc,char **argv)
{
    mglFLTK gr("test");
    gr.RunThr();    // <-- need MathGL version which use pthread
    for(int i=0;i<10;i++)   // do calculation
    {
        long_calculations();// which can be very long
        pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
        gr.Clf();           // make new drawing
        gr.Line(mglPoint(),pnt,"Ar2");
        char str[10] = "i=0";   str[3] = '0'+i;
        gr.Update();        // update window
    }
    return 0;   // finish calculations and close the window
}
#else       // just default samples
int test_wnd(mglGraph *gr);
int sample(mglGraph *gr);
int sample_1(mglGraph *gr);
int sample_2(mglGraph *gr);
int sample_3(mglGraph *gr);
int sample_d(mglGraph *gr);
//-----------------------------------------------------------------------------
int main(int argc,char **argv)
{
    mglFLTK *gr;
    char key = 0;
    if(argc>1)  key = argv[1][0]!='-' ? argv[1][0]:argv[1][1];
    else    printf("You may specify argument '1', '2', '3' or 'd' for viewing examples of 1d, 2d, 3d or dual plotting\n");
    switch(key)
    {
    case '0':   gr = new mglFLTK((mglDraw *)NULL,"1D plots");   break;
    case '1':   gr = new mglFLTK(sample_1,"1D plots");  break;
    case '2':   gr = new mglFLTK(sample_2,"2D plots");  break;
    case '3':   gr = new mglFLTK(sample_3,"3D plots");  break;
    case 'd':   gr = new mglFLTK(sample_d,"Dual plots");break;
    case 't':   gr = new mglFLTK(test_wnd,"Testing");   break;
    default:    gr = new mglFLTK(sample,"Drop and waves");  break;
    }
    if(key=='0')
    {   gr->Rotate(40,60);  gr->Box();  gr->Light(true);    gr->FSurf("sin(4*pi*x*y)"); gr->Update();   }
    gr->Run();  return 0;
}
#endif
//-----------------------------------------------------------------------------

0 个答案:

没有答案