我使用msys64 - mingw32(在Windows 7,64位上)使用提供的makefile构建第三方库(libosmscout)。我主要感兴趣的是库中的一个特定示例(Demos / src / DrawMapCairo)。随着makefile完成库的建立成功,包括演示。感兴趣的示例控制台应用程序工作正常。
然而,我的意图是使用Code :: Blocks IDE创建我自己的应用程序,它将使用示例应用程序的功能。因此,我尝试在Code :: Blocks(新项目 - >控制台应用程序,GCC 5.1 MinGW)中构建示例。过了一会儿,我设法成功构建了0错误/警告。但应用程序不起作用,它与sigsegv错误崩溃。 “cout调试”并进入调试器表明问题似乎是(或开始)在行
osmscout :: DatabaseRef数据库(new osmscout :: Database(databaseParameter));
main()的源代码:
#includes...
static const double DPI=96.0;
int main(int argc, char* argv[])
{
std::string map;
std::string style;
std::string output;
size_t width,height;
double lon,lat,zoom;
if (argc!=9) {
std::cerr << "DrawMap <map directory> <style-file> <width> <height> <lon> <lat> <zoom> <output>" << std::endl;
return 1;
}
map=argv[1];
style=argv[2];
//next 6 lines not exactly as in source, but for shorter code:
osmscout::StringToNumber(argv[3],width);
osmscout::StringToNumber(argv[4],height);
sscanf(argv[5],"%lf",&lon);
sscanf(argv[6],"%lf",&lat);
sscanf(argv[7],"%lf",&zoom);
output=argv[8];
osmscout::DatabaseParameter databaseParameter;
osmscout::DatabaseRef database(new osmscout::Database(databaseParameter));
osmscout::MapServiceRef mapService(new osmscout::MapService(database));
if (!database->Open(map.c_str())) {
std::cerr << "Cannot open database" << std::endl;
return 1;
}
osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig (database->GetTypeConfig()));
if (!styleConfig->Load(style)) {
std::cerr << "Cannot open style" << std::endl;
}
cairo_surface_t *surface;
cairo_t *cairo;
surface=cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height);
if (surface!=NULL) {
cairo=cairo_create(surface);
if (cairo!=NULL) {
osmscout::MercatorProjection projection;
osmscout::MapParameter drawParameter;
osmscout::AreaSearchParameter searchParameter;
osmscout::MapData data;
osmscout::MapPainterCairo painter(styleConfig);
drawParameter.SetFontSize(3.0);
projection.Set(lon,
lat,
osmscout::Magnification(zoom),
DPI,
width,
height);
std::list<osmscout::TileRef> tiles;
mapService->LookupTiles(projection,tiles);
mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles);
mapService->ConvertTilesToMapData(tiles,data);
if (painter.DrawMap(projection,
drawParameter,
data,
cairo)) {
if (cairo_surface_write_to_png(surface,output.c_str())!=CAIRO_STATUS_SUCCESS) {
std::cerr << "Cannot write PNG" << std::endl;
}
}
cairo_destroy(cairo);
}
else {
std::cerr << "Cannot create cairo cairo" << std::endl;
}
cairo_surface_destroy(surface);
}
else {
std::cerr << "Cannot create cairo surface" << std::endl;
}
return 0;
}
如何准确找到问题并解决问题?让我感到困惑的是,用makefile构建的相同的代码工作正常。
修改
运行GDB(Gnu Debugger,gdb32.exe)然后运行bt(backtrace)后,我得到以下输出:
[New Thread 3900.0x538]
Program received signal SIGSEGV, Segmentation fault.
0x777ec159 in ntdll!RtlDecodeSystemPointer ()
from C:\Windows\SysWOW64\ntdll.dll
(gdb)
(gdb) bt
#0 0x777e3c28 in ntdll!RtlQueryPerformanceCounter ()
from C:\Windows\SysWOW64\ntdll.dll
#1 0x00000028 in ?? ()
#2 0x00870000 in ?? ()
#3 0x777ec1ed in ntdll!RtlDecodeSystemPointer ()
from C:\Windows\SysWOW64\ntdll.dll
#4 0x777ec13e in ntdll!RtlDecodeSystemPointer ()
from C:\Windows\SysWOW64\ntdll.dll
#5 0x777e3541 in ntdll!RtlQueryPerformanceCounter ()
from C:\Windows\SysWOW64\ntdll.dll
#6 0x00000010 in ?? ()
#7 0x00000028 in ?? ()
#8 0x008700c4 in ?? ()
#9 0x77881dd3 in ntdll!RtlpNtEnumerateSubKey ()
from C:\Windows\SysWOW64\ntdll.dll
#10 0x7783b586 in ntdll!RtlUlonglongByteSwap ()
from C:\Windows\SysWOW64\ntdll.dll
#11 0x00870000 in ?? ()
#12 0x777e3541 in ntdll!RtlQueryPerformanceCounter ()
from C:\Windows\SysWOW64\ntdll.dll
#13 0x00000010 in ?? ()
#14 0x00000000 in ?? ()
(gdb)
这个错误意味着什么以及如何找到导致它纠正错误的原因?