简体   繁体   English

最初用 Linux 编写的 C 程序,现在使用 Cygwin 移植到 Windows(使用 gcc 编译)

[英]C program originally written in Linux, now porting to Windows using Cygwin (compile w/ gcc)

I'm working on a fairly lengthy project that was originally written in C on a Linux machine.我正在处理一个相当冗长的项目,该项目最初是在 Linux 机器上用 C 编写的。 I need to port it to windows and am trying to use the gcc compiler in Cygwin as the "easiest" method of transfer.我需要将它移植到 Windows 并尝试在 Cygwin 中使用 gcc 编译器作为“最简单”的传输方法。

The program was originally written a long time ago and has been through many hands.该程序最初是很久以前编写的,已经经过了很多人的手。 It has always been run on Linux before and has had no problems.它之前一直在Linux上运行,没有任何问题。 There are a number of parts to the program most of which compile and run fine under both Linux and Cygwin.该程序有许多部分,其中大部分都可以在 Linux 和 Cygwin 下正常编译和运行。 However, there is one portion of the project which compiles in Cygwin but gives a segmentation fault before doing anything as far as I can tell (same code works fine in Linux).但是,该项目的一部分在 Cygwin 中编译,但据我所知,在执行任何操作之前会出现分段错误(相同的代码在 Linux 中运行良好)。

I've put in a number of printf() statements to see if I can narrow it down but it seems to give the seg fault before it does anything at all (ie, my first printf() is the first thing after main(){...).我已经放入了一些 printf() 语句,看看我是否可以缩小它的范围,但它似乎在它做任何事情之前就给出了段错误(即,我的第一个 printf() 是 main() 之后的第一件事{...)。 I've used the -Wall option with gcc to try and see if there are any "obvious" warnings/errors but don't see anything that jumps out.我在 gcc 中使用了 -Wall 选项来尝试查看是否有任何“明显”的警告/错误,但没有看到任何跳出的内容。 They're mostly just warnings about expecting "int" when a "long int" is passed but these are identical to the warnings I get using -Wall in Linux as well.它们主要是关于在传递“long int”时期望“int”的警告,但这些警告与我在 Linux 中使用 -Wall 得到的警告相同。

Does anyone have a suggestion on what kinds of things I should look for in trying to make the code compatible for Cygwin and/or thoughts on what might be causing the code to give a seg fault before even getting going in Cygwin?在尝试使代码与 Cygwin 兼容时,是否有人建议我应该寻找哪些类型的东西和/或关于可能导致代码在进入 Cygwin 之前出现段错误的原因的想法? (I'd post some code but it's several thousand lines). (我会发布一些代码,但它有几千行)。

Thanks for your help!谢谢你的帮助!

EDIT: Thanks for the suggestions.编辑:感谢您的建议。 I went through the gdb with results shown below.我浏览了 gdb,结果如下所示。 I then spent the better part of yesterday trying MinGW in Linux.然后我花了昨天的大部分时间在 Linux 中尝试 MinGW。 Still with no success.仍然没有成功。 Could either/both problems have something to do with the architecture (Sandy Bridge) or the OS (Windows 7 64 bit)??是否有一个/两个问题都与架构(Sandy Bridge)或操作系统(Windows 7 64 位)有关?? I get a seg fault as soon as the program loads - it doesn't even make it past main(...)一旦程序加载,我就会收到段错误 - 它甚至没有超过 main(...)

If you want just the exe in the windows environment and won't need to rebuild it there you can try using MinGW and the command i586-mingw32msvc-g++ or i586-mingw32msvc-gcc in linux to cross-compile.如果您只想要 Windows 环境中的 exe 而不需要在那里重建它,您可以尝试使用 MinGW 和命令i586-mingw32msvc-g++i586-mingw32msvc-gcc在 linux 中进行交叉编译。 It's worked for me;它对我有用; hopefully it works for you.希望它对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM