Compile Maxmind C library with visual studio 2010

陌路散爱 提交于 2019-12-13 04:53:43

问题


does anybony compiled successfully the Maxmind C library on Visual Studio 2010? I'm not able to compile it on Windows because I get a lot of errors regarding files not found like unistd.h


回答1:


The error that you are seeing is probably because you are including GeoIPUpdate which isn't really necessary. GeoIPUpdate is a standalone script for updating the databases, and isn't necessary to use the APIs themselves. Try removing that to see if that resolves your issues.

Additionally, to get version 1.4.8 to compile for me on Visual Studio 2005 I had to do the following additional steps:

  1. In GeoIPCity.c change the inclusion of the GeoIP*.h files to use "" instead of <>
  2. In GeoIPCity.h change the inclusion of GeoIP.h to use "" instead of <>
  3. In GeoIP.h add #define ssize_t long
  4. In GeoIP.c change PACKAGE_VERSION to "1.4.8"
  5. In GeoIPCity.c you cannot use a static const when declaring an array. Change the definition of tmp_fixed_record to be unsigned char tmp_fixed_record[6+4]; //Can't use CITYCONFIDENCEDIST_FIXED_RECORD in declaration
  6. In GeoIPCity.c declare t at the start of _extract_record().
  7. Add main function to GeoIPCity.c to get your code to compile.
  8. Download the zlib125.dll.zip files from http://www.winimage.com/zLibDll/index.html. Extract these files and save the dllx64/* and static64/zlibstat.lib files to a location on disk. Now, in Visual Studio go to Project->Properties->Linker->Input and under "Additional Dependencies" add "ws2_32.lib zlibwapi.lib zlibstat.lib". Next, Under Linker->General go to "Additional Library Dependencies" and add the location of where you saved the files above.
  9. In GeoIPCity.c and GeoIP.c pread is undefined. Add the following definition to each of these files:

#define pread my_pread
static size_t my_pread( int file_no, void *buffer, size_t size, size_t offset )
{
  if (_lseek( file_no, (long)offset, SEEK_SET) == offset)
    return _read(file_no, buffer, (int)size);
  else
    return -1L;
}
Additionally, add #include <io.h> to GeoIP.h so that _lseek and _read are included.

来源:https://stackoverflow.com/questions/12187040/compile-maxmind-c-library-with-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!