【问题标题】:Compile Maxmind C library with visual studio 2010使用 Visual Studio 2010 编译 Maxmind C 库
【发布时间】:2012-08-29 21:51:41
【问题描述】:

是否有人在 Visual Studio 2010 上成功编译了 Maxmind C 库?我无法在 Windows 上编译它,因为我收到很多关于 unistd.h 等未找到文件的错误

【问题讨论】:

    标签: c++ visual-studio-2010 geoip


    【解决方案1】:

    您看到的错误可能是因为您包含了并非真正需要的 GeoIPUpdate。 GeoIPUpdate 是用于更新数据库的独立脚本,不需要使用 API 本身。尝试删除它,看看是否能解决您的问题。

    此外,为了在 Visual Studio 2005 上为我编译 1.4.8 版,我必须执行以下附加步骤:

    1. 在 GeoIPCity.c 中将 GeoIP*.h 文件的包含更改为使用“”而不是
    2. 在 GeoIPCity.h 中将 GeoIP.h 的包含更改为使用“”而不是
    3. 在 GeoIP.h 中添加 #define ssize_t long
    4. 在 GeoIP.c 中将 PACKAGE_VERSION 更改为“1.4.8”
    5. 在 GeoIPCity.c 中声明数组时不能使用static const。将tmp_fixed_record 的定义更改为 unsigned char tmp_fixed_record[6+4]; //Can't use CITYCONFIDENCEDIST_FIXED_RECORD in declaration
    6. 在 GeoIPCity.c 中,在 _extract_record() 的开头声明 t
    7. 将 main 函数添加到 GeoIPCity.c 以编译您的代码。
    8. http://www.winimage.com/zLibDll/index.html 下载zlib125.dll.zip 文件。提取这些文件并将 dllx64/* 和 static64/zlibstat.lib 文件保存到磁盘上的某个位置。 现在,在 Visual Studio 中转到 Project->Properties->Linker->Input 并在“Additional Dependencies”下添加“ws2_32.lib zlibwapi.lib zlibstat.lib”。接下来,在 Linker->General 下转到 “其他库依赖项”并添加您保存上述文件的位置。
    9. 在 GeoIPCity.c 和 GeoIP.c 中 pread 未定义。将以下定义添加到每个文件中:

    #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;
    }
    
    此外,将#include <io.h> 添加到GeoIP.h,以便包含_lseek_read

    【讨论】:

    • 谢谢,我会接受你的回答,尽管我通过将 C# 版本移植到 C++ 来修复它
    猜你喜欢
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2011-06-13
    • 2011-08-02
    • 1970-01-01
    • 2015-06-30
    • 2011-03-04
    相关资源
    最近更新 更多