需要帮助将Win32 C ++移植到Unix

时间:2009-09-23 19:20:30

标签: c++ windows unix cross-platform

我正在寻找帮助将此Windows工具移植到Unix(Mac / OSX);

的帮助

http://www.oxyron.de/html/netdrive01src.zip

首先我想知道,如果有人花点时间快速查看(小)源代码,如果这是一个相当直接的任务。

其次,非常感谢有关移植代码的任何提示。

我已经尝试过编译它(使用Xcode / G ++)但它会抛出80多个错误,其中许多错误似乎是常量,例如“_MAX_FNAME”,我认为这是一个定义最大文件名的系统常量长度。我试图查看标准的C标题(在我的Mac上),但是当我在SYSLIMITS.H(NAME_MAX)中找到类似的常量时,我​​似乎仍然没有取得多大进展。

3 个答案:

答案 0 :(得分:3)

似乎有一些不同类型的错误:

main.cpp:8:19: error: conio.h: No such file or directory
main.cpp:61: error: ‘_kbhit’ was not declared in this scope

conio.h是Window的控制台io标题。 _kbhit是其中的一个功能。

main.cpp:17: warning: deprecated conversion from string constant to ‘char*’

字符串常量在ANSI C ++中的类型为const char *。代码中还有一些奇怪的字符串函数,如果您使用C ++ std :: string而不是使用new的C字符串,则不会存在。

vbinary.cpp:5:16: error: io.h: No such file or directory

vdirectory.cpp:91: error: ‘_findfirst’ was not declared in this scope
vdirectory.cpp:99: error: ‘_findnext’ was not declared in this scope
vdirectory.cpp:101: error: ‘_findclose’ was not declared in this scope
vfile.cpp:19: error: ‘_MAX_DRIVE’ was not declared in this scope
vfile.cpp:20: error: ‘_MAX_DIR’ was not declared in this scope
vfile.cpp:21: error: ‘_MAX_FNAME’ was not declared in this scope
vfile.cpp:22: error: ‘_MAX_EXT’ was not declared in this scope

io.h是另一个Microsoft标头,具有导航目录和与它们一起使用的宏的功能。请改用dirent.h中的功能。诸如VDirectory::CreatePath之类的函数假定存在单独的驱动器号; unix文件系统没有,所以最好为实现创建完全独立的类,而不是尝试使用#ifdef将两个单独的主体放入每个函数中,并使用一个#ifdef来选择适当的类。主

_MAX_FNAME等常量同时出现在io.h和Microsoft的stdlib.h中。它们不在标准stdlib.h中,也不限制其输入大小的函数。 POSIX版本使用NAME_MAX

答案 1 :(得分:1)

如果大部分错误与预处理程序定义有关,则可以在编译器命令行中添加这些定义。例如,对于g ++,这将是-D _MAX_FNAME=NAME_MAX选项(或适用的任何值)。

答案 2 :(得分:0)

简要介绍一下代码(grep "#include <"),可以看出所有平台依赖都在nethost头中。此标头包含处理平台独立性所需的所有#ifdef:

#ifdef WIN32
    #define WIN32_LEAN_AND_MEAN 1
    #include <winsock2.h>
#else
    #ifdef __APPLE__
        #include <netinet/in.h>
    #endif

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <unistd.h>
    #include <arpa/inet.h>
    #include <sys/select.h>
#endif

看起来好。乍一看。