简体   繁体   中英

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. I have to compile so it will run linux using gcc 4.4.1 C99.

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. However, has it has been developed using VS, I don't have any makefile to use.

I could write a make file. But I am not sure about the dependences as there are about 20 files all together (*.c and *.h).

I am just wondering how can I write a makefile from a visual studio project? 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 can generate a VS.net solution file, and it can generate a 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.

This should do most of what you want.

Start with a very simple 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).

Now you can make and run your app in Unix simply with:

$ 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.

For private projects, keep your makefiles simple and clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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