简体   繁体   English

在Windows和Linux上编译

[英]compiling on Windows and Linux

I am just looking for some guidelines, as this might seem like a very open question. 我只是在寻找一些指导原则,因为这似乎是一个非常开放的问题。

I have a project that has been compiled using Visual Studio 2008 sp1. 我有一个使用Visual Studio 2008 sp1编译的项目。 I have to compile so it will run linux using gcc 4.4.1 C99. 我必须进行编译,以便它将使用gcc 4.4.1 C99运行linux。

It is a demo application that I didn't write myself. 这不是我自己写的演示应用程序。

The source code is written so it can be cross-platform (linux, windows), so the code will compile and run on linux. 编写了源代码,因此它可以是跨平台的(Linux,Windows),因此代码可以在Linux上编译并运行。 However, has it has been developed using VS, I don't have any makefile to use. 但是,如果它是使用VS开发的,则没有任何makefile可以使用。

I could write a make file. 我可以写一个make文件。 But I am not sure about the dependences as there are about 20 files all together (*.c and *.h). 但是我不确定这种依赖性,因为总共大约有20个文件(* .c和* .h)。

I am just wondering how can I write a makefile from a visual studio project? 我只是想知道如何从Visual Studio项目中编写Makefile? Is there any settings I can use? 我可以使用任何设置吗? and what depends on what? 什么取决于什么? Anything else? 还要别的吗?

Many thanks for any suggestions, 非常感谢您的任何建议,

One tool that you can use is CMake. 可以使用的一种工具是CMake。 CMake can generate a VS.net solution file, and it can generate a Unix makefile. CMake可以生成VS.net解决方案文件,并且可以生成Unix makefile。 This way is not easy, nor is it the without its bumps in the road. 这种方法并不容易,也不容易遇到障碍。 (Especially when the build sequence gets complex) (特别是当构建顺序变得复杂时)

The makedepend utility will scan the C files you give it, using C preprocessing rules to determine their dependencies and output them to a Makefile. makedepend实用程序将扫描您提供给它的C文件,使用C预处理规则确定它们的依赖关系并将它们输出到Makefile。

This should do most of what you want. 这应该可以满足您的大部分需求。

Start with a very simple Makefile: 从一个非常简单的Makefile开始:

theapp: *.c *.h Makefile
    gcc *.c -o theapp

Those two lines will get you 90% of the way there (and, in a lot of cases, 100% of the way). 这两行将为您提供90%的访问方式(在很多情况下为100%的访问方式)。

Now you can make and run your app in Unix simply with: 现在,您只需使用以下命令即可在Unix中制作和运行您的应用程序:

$ make && ./theapp

I don't recommend that you use those complex Makefile generators like automake unless you plan on releasing this stuff to the world. 建议您使用像automake这样的复杂Makefile生成器, 除非您计划将这些东西发布给全世界。

For private projects, keep your makefiles simple and clean. 对于私有项目,请使您的makefile简单,干净。

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

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