使用使跨平台编译 [英] Using make for cross platform compilation

查看:101
本文介绍了使用使跨平台编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发的Linux和Win32下一个C项目。在'交付'是一个共享库,所有的发展是与GNU工具链在Linux下完成的。我使用一个Makefile来编译共享库。

时不时地,我不得不从同一个SRC建立在Win32下一个.dll。

我在Win32的盒子,这样我可以用make并获得的的减少从编译器(相比于MSVC)投诉安装MinGW的。我在那里的SRC code两个平台上编译一个阶段

但Linux的Makefile和Win32 Makefile文件是不同的。我很好奇,如何以最佳方式处理这一点 - 我应该:


  1. 有2个生成文件,例如Makefile文件Linux和Makefile.WIN32,然后运行使-f Makefile.WIN32 在Windows中


  2. 我应该做在一个Makefile中不同的目标,做一些像让WIN32 在Windows中


  3. 我应该沟制作和使用CMake的(是值得汁挤对于这样一个简单的项目,即1共享库)



解决方案

使用一个单一的make文件,并把平台的细节中的条件,如:

  IFEQ($(OS),Windows_NT)
    DLLEXT:= .DLL
其他
    DLLEXT:=的.so
万一DLL:= libfoo的$(DLLEXT)lib目录下:$(DLL)

I am currently developing a C project under Linux and Win32. The 'deliverable' is a shared library, and all the development is done under Linux with the GNU tool chain. I am using a Makefile to compile the shared library.

Every now and then I have to build a .dll under Win32 from the same src.

I've installed MinGW on the Win32 box such that I can use make and get far fewer complaints from the compiler (in comparison to MSVC). I'm at a stage where the src code compiles on both platforms

But the Linux Makefile and Win32 Makefile are different. I'm curious as how to best handle this - should I:

  1. have 2 makefiles, e.g. Makefile for linux and Makefile.WIN32 and then run make -f Makefile.WIN32 on the Windows box

  2. Should I make a different target in a single Makefile and do something like make WIN32 on the Windows box

  3. Should I ditch make and use CMake (is the juice worth the squeeze for such a simple project, i.e. 1 shared library)

解决方案

Use a single make file and put the platform-specifics in conditionals, eg

ifeq ($(OS),Windows_NT)
    DLLEXT := .dll
else
    DLLEXT := .so
endif

DLL := libfoo$(DLLEXT)

lib : $(DLL)

这篇关于使用使跨平台编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆