원래 Microsoft Windows용으로 작성된 C++ 소스 코드를 Gnu/linux로 크로스 컴파일할 수 있습니까?

원래 Microsoft Windows용으로 작성된 C++ 소스 코드를 Gnu/linux로 크로스 컴파일할 수 있습니까?

소스 코드에서 Windows용 소프트웨어를 컴파일하려고 합니다. 제가 특별히 컴파일하려고 하는 소프트웨어는 Keeperfx for Dungeon Keeper라는 애플리케이션입니다. 나는 이 게임을 좋아하기 때문에 Linux에서 소스 코드를 컴파일하고 작동하는지 확인해야겠다고 생각했습니다. 그러나 나는 그렇게 운이 좋지 않았습니다.

make명령을 실행하면 다음과 같은 출력이 제공됩니다.

mkdir -p obj/std
Building file: src/main.cpp
g++ -I"directx/include" -I"sdl/include" -I"libav/include" -c -fmessage-length=0 -Wall -Wno-sign-compare -Wno-unused-parameter -Wno-strict-aliasing -Wno-unknown-pragmas -MMD -MP -MF"obj/std/main.d" -MT"obj/std/main.d" -march=i686 -fno-omit-frame-pointer -O3   -DBFDEBUG_LEVEL=0  -o"obj/std/main.o" "src/main.cpp"
src/main.cpp:1:0: error: CPU you selected does not support x86-64 instruction set
 #pragma region includes
 ^
src/main.cpp:1:0: error: CPU you selected does not support x86-64 instruction set
Makefile:658: recipe for target 'obj/std/main.o' failed
make: *** [obj/std/main.o] Error 1

그래서 나는 mingw를 사용할 것이라고 생각했습니다. 하지만 계속 오류가 발생합니다.

../src/bflib_crash.c: In function ‘sigstr’:
../src/bflib_crash.c:77:10: error: ‘SIGBREAK’ undeclared (first use in this function)
     case SIGBREAK : return "Ctrl-Break (Win32)";
          ^
../src/bflib_crash.c:77:10: note: each undeclared identifier is reported only once for each function it appears in
../src/bflib_crash.c: In function ‘LbErrorParachuteInstall’:
../src/bflib_crash.c:189:12: error: ‘SIGBREAK’ undeclared (first use in this function)
     signal(SIGBREAK,ctrl_handler);
            ^
In file included from ../src/bflib_dernc.c:26:0:
/usr/include/fcntl.h:202:12: error: conflicting types for ‘creat’
 extern int creat (const char *__file, mode_t __mode) __nonnull ((1));
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:314:15: note: previous declaration of ‘creat’ was here
   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_D
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:283:12: error: conflicting types for ‘chmod’
 extern int chmod (const char *__file, __mode_t __mode)
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:311:15: note: previous declaration of ‘chmod’ was here
   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRE
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:311:17: error: conflicting types for ‘umask’
 extern __mode_t umask (__mode_t __mask) __THROW;
                 ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:328:15: note: previous declaration of ‘umask’ was here
   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:320:12: error: conflicting types for ‘mkdir’
 extern int mkdir (const char *__path, __mode_t __mode)
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:267:15: note: previous declaration of ‘mkdir’ was here
   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_fileio.c:28:0:
/usr/include/fcntl.h:202:12: error: conflicting types for ‘creat’
 extern int creat (const char *__file, mode_t __mode) __nonnull ((1));
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:314:15: note: previous declaration of ‘creat’ was here
   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_D
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:283:12: error: conflicting types for ‘chmod’
 extern int chmod (const char *__file, __mode_t __mode)
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:311:15: note: previous declaration of ‘chmod’ was here
   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRE
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:311:17: error: conflicting types for ‘umask’
 extern __mode_t umask (__mode_t __mask) __THROW;
                 ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:328:15: note: previous declaration of ‘umask’ was here
   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:320:12: error: conflicting types for ‘mkdir’
 extern int mkdir (const char *__path, __mode_t __mode)
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:267:15: note: previous declaration of ‘mkdir’ was here
   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
../src/bflib_fileio.c: In function ‘LbFileOpen’:
../src/bflib_fileio.c:237:43: error: ‘O_BINARY’ undeclared (first use in this function)
         rc = _sopen(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_IREAD|S_IWRITE
                                           ^
../src/bflib_fileio.c:237:43: note: each undeclared identifier is reported only once for each function it appears in
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_keybrd.c:25:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
../src/bflib_math.c: In function ‘LbRandomSeries’:
../src/bflib_math.c:746:11: warning: implicit declaration of function ‘_lrotr’ [-Wimplicit-function-declaration]
   *seed = _lrotr(i, 13);
           ^
../src/bflib_tcpsp.c:26:26: fatal error: SDL2/SDL_net.h: No such file or directory
 #include <SDL2/SDL_net.h>
                          ^
compilation terminated.
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_video.c:27:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_vidsurface.c:25:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
../src/config.c: In function ‘recognize_conf_command’:
../src/config.c:275:13: warning: implicit declaration of function ‘strnicmp’ [-Wimplicit-function-declaration]
         if (strnicmp(buf+(*pos), commands[i].name, cmdname_len) == 0)
             ^
../src/config.c: In function ‘get_language_lwrstr’:
../src/config.c:424:3: warning: implicit declaration of function ‘strlwr’ [-Wimplicit-function-declaration]
   strlwr(lang_str);
   ^
../src/front_network.c: In function ‘net_write_config_file’:
../src/front_network.c:503:9: warning: implicit declaration of function ‘strupr’ [-Wimplicit-function-declaration]
         strupr(net_config_info.str_atz);
         ^
../src/lvl_filesdk1.c: In function ‘get_level_number_from_file_name’:
../src/lvl_filesdk1.c:108:7: warning: implicit declaration of function ‘strnicmp’ [-Wimplicit-function-declaration]
   if (strnicmp(fname,"map",3) != 0)
       ^
../src/lvl_script.c: In function ‘get_next_word’:
../src/lvl_script.c:446:9: warning: implicit declaration of function ‘strupr’ [-Wimplicit-function-declaration]
         strupr(param);
         ^
../src/lvl_script.c: In function ‘get_map_location_code_name’:
../src/lvl_script.c:792:9: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
         itoa(apt->num, name, 10);
         ^
nicholas@LinuxNick ~/.apps/keeperfx/bin $ sudo i686-w64-mingw32-gcc-win32 -I/usr/include -L/usr/local/lib -liconv ../src/*.c -o keeperfx/
[sudo] password for nicholas: 
../src/bflib_crash.c: In function ‘sigstr’:
../src/bflib_crash.c:77:10: error: ‘SIGBREAK’ undeclared (first use in this function)
     case SIGBREAK : return "Ctrl-Break (Win32)";
          ^
../src/bflib_crash.c:77:10: note: each undeclared identifier is reported only once for each function it appears in
../src/bflib_crash.c: In function ‘LbErrorParachuteInstall’:
../src/bflib_crash.c:189:12: error: ‘SIGBREAK’ undeclared (first use in this function)
     signal(SIGBREAK,ctrl_handler);
            ^
In file included from ../src/bflib_dernc.c:26:0:
/usr/include/fcntl.h:202:12: error: conflicting types for ‘creat’
 extern int creat (const char *__file, mode_t __mode) __nonnull ((1));
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:314:15: note: previous declaration of ‘creat’ was here
   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_D
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:283:12: error: conflicting types for ‘chmod’
 extern int chmod (const char *__file, __mode_t __mode)
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:311:15: note: previous declaration of ‘chmod’ was here
   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRE
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:311:17: error: conflicting types for ‘umask’
 extern __mode_t umask (__mode_t __mask) __THROW;
                 ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:328:15: note: previous declaration of ‘umask’ was here
   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_dernc.c:27:0:
/usr/include/sys/stat.h:320:12: error: conflicting types for ‘mkdir’
 extern int mkdir (const char *__path, __mode_t __mode)
            ^
In file included from ../src/bflib_dernc.c:25:0:
/usr/share/mingw-w64/include/io.h:267:15: note: previous declaration of ‘mkdir’ was here
   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_fileio.c:28:0:
/usr/include/fcntl.h:202:12: error: conflicting types for ‘creat’
 extern int creat (const char *__file, mode_t __mode) __nonnull ((1));
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:314:15: note: previous declaration of ‘creat’ was here
   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_D
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:283:12: error: conflicting types for ‘chmod’
 extern int chmod (const char *__file, __mode_t __mode)
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:311:15: note: previous declaration of ‘chmod’ was here
   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRE
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:311:17: error: conflicting types for ‘umask’
 extern __mode_t umask (__mode_t __mask) __THROW;
                 ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:328:15: note: previous declaration of ‘umask’ was here
   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
In file included from ../src/bflib_fileio.c:29:0:
/usr/include/sys/stat.h:320:12: error: conflicting types for ‘mkdir’
 extern int mkdir (const char *__path, __mode_t __mode)
            ^
In file included from ../src/bflib_basics.h:23:0,
                 from ../src/bflib_fileio.h:23,
                 from ../src/bflib_fileio.c:22:
/usr/share/mingw-w64/include/io.h:267:15: note: previous declaration of ‘mkdir’ was here
   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
               ^
../src/bflib_fileio.c: In function ‘LbFileOpen’:
../src/bflib_fileio.c:237:43: error: ‘O_BINARY’ undeclared (first use in this function)
         rc = _sopen(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_IREAD|S_IWRITE
                                           ^
../src/bflib_fileio.c:237:43: note: each undeclared identifier is reported only once for each function it appears in
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_keybrd.c:25:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
../src/bflib_math.c: In function ‘LbRandomSeries’:
../src/bflib_math.c:746:11: warning: implicit declaration of function ‘_lrotr’ [-Wimplicit-function-declaration]
   *seed = _lrotr(i, 13);
           ^
../src/bflib_tcpsp.c:26:26: fatal error: SDL2/SDL_net.h: No such file or directory
 #include <SDL2/SDL_net.h>
                          ^
compilation terminated.
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_video.c:27:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
In file included from /usr/include/bits/errno.h:24:0,
                 from /usr/include/errno.h:35,
                 from /usr/share/mingw-w64/include/intrin.h:65,
                 from /usr/include/SDL2/SDL_cpuinfo.h:44,
                 from /usr/include/SDL2/SDL.h:38,
                 from ../src/bflib_vidsurface.c:25:
/usr/include/linux/errno.h:1:23: fatal error: asm/errno.h: No such file or directory
compilation terminated.
../src/config.c: In function ‘recognize_conf_command’:
../src/config.c:275:13: warning: implicit declaration of function ‘strnicmp’ [-Wimplicit-function-declaration]
         if (strnicmp(buf+(*pos), commands[i].name, cmdname_len) == 0)
             ^
../src/config.c: In function ‘get_language_lwrstr’:
../src/config.c:424:3: warning: implicit declaration of function ‘strlwr’ [-Wimplicit-function-declaration]
   strlwr(lang_str);
   ^
../src/front_network.c: In function ‘net_write_config_file’:
../src/front_network.c:503:9: warning: implicit declaration of function ‘strupr’ [-Wimplicit-function-declaration]
         strupr(net_config_info.str_atz);
         ^
../src/lvl_filesdk1.c: In function ‘get_level_number_from_file_name’:
../src/lvl_filesdk1.c:108:7: warning: implicit declaration of function ‘strnicmp’ [-Wimplicit-function-declaration]
   if (strnicmp(fname,"map",3) != 0)
       ^
../src/lvl_script.c: In function ‘get_next_word’:
../src/lvl_script.c:446:9: warning: implicit declaration of function ‘strupr’ [-Wimplicit-function-declaration]
         strupr(param);
         ^
../src/lvl_script.c: In function ‘get_map_location_code_name’:
../src/lvl_script.c:792:9: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
         itoa(apt->num, name, 10);
         ^

i686-w64-mingw32-gcc-win32 -I/usr/include -L/usr/local/lib -liconv ../src/*.c명령을 사용하여 컴파일 하고 있습니다 . 그런데 출력 위치를 추가해도 출력 파일이 출력되지 않습니다.

여기서 또 무엇을 해야할지 모르겠습니다.

내 시스템은 Cinnamon에서 64비트 Linux Mint 버전 18.1을 실행하고 있습니다.

답변1

첫 번째 오류 세트는 소스 코드가 32비트 대상에만 사용 가능하기 때문에 발생합니다. KeeperFX를 빌드할 때 다음을 실행하여 강제로 적용할 수 있습니다(컴파일러가 올바르게 설정된 경우).

make CPP="g++ -m32"

그러나 빌드할 때 누락된 헤더( windows.h, winbase.h, io.h) 가 발생합니다 . 이는 코드가 Windows용으로 작성되었으며 이식성 문제가 없음을 나타냅니다. "순수한 C/C++"가 아닙니다.basetyps.hsrc/main.cpp

KeeperFX는 적어도 일부 버전의 MinGW 또는 MinGW-w64를 사용한 빌드를 지원하는 것으로 보이지만 설명에 언급된 대로 Linux에서는 Windows 바이너리 빌드만 허용합니다. 따라서 다음을 사용하여 Linux에서 빌드할 수 있습니다.

make CROSS_COMPILE=i686-w64-mingw32-

적절한 크로스 컴파일러가 필요하지만 결과 바이너리를 Linux에서 실행하려면 Wine이 필요합니다. (Mint에서 적절한 크로스 컴파일러는 입니다 g++-mingw-w64.)

그것가능한큰 노력 없이도 KeeperFX를 SDL로 포팅하는 것이 가능하지만 아직 자세히 살펴보지는 않았습니다.

관련 정보