Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

C++ cross-compiler from Windows to Linux


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

crosstool-ng supports building cross-compilers with cygwin host.

Overview:

  • Install cygwin, with development packages
  • Download crosstool-ng
  • Extract the tarball (tar xvjf crosstool-ng*)
  • Run ./configure
  • When configure complains about a missing tool, go back to cygwin setup and install the corresponding package (e.g. flex, libtool, ncurses-devel) You'll need at least the following:
    • Devel/gperf
    • Devel/bison
    • Devel/byacc
    • Devel/wget
    • Devel/patch
    • Devel/make (GNU version)
    • Devel/automake 1.10+
    • Libs/libncursesw10
    • Libs/libncursesw10-devel
  • make
  • make install
  • Create a new directory for building the cross-compiler, e.g. /usr/src/cross-linux-gnu-root
  • Enable system-wide case sensitivity support in the registry (see https://superuser.com/questions/266110/how-do-you-make-windows-7-fully-case-sensitive-with-respect-to-the-filesystem#answer-842670)
  • Mount the directory case-sensitive (e.g. mount c:/cygwin/usr/src/cross-linux-gnu-root /usr/src/cross-linux-gnu -o binary,posix=1)
  • From inside the cross-compiler build directory, ct-ng menuconfig
  • In the menus, set target architecture to x86 (probably) and subarchitecture to i686 (avoids GCC 4.8 issues, thanks osm0sis), target kernel to linux, and target C library to glibc, and enable the C++ compiler.
  • To work around make 4.0 issues, also enable EXPERIMENTAL in Paths and misc options then, go in Companion tools (at top-level) and enable Build some companion tools and then make 3.81 (Thanks osm0sis)
  • wget has issues with the latest kernel.org certificates so use the .wgetrc method in this accepted answer: How do I fix certificate errors when running wget on an HTTPS URL in Cygwin? (Thanks osm0sis)
  • Currently 3 file patches are required to avoid further errors:
  • ct-ng build

Of course, this is NOT going to enable you to build linux applications from inside Visual Studio. (VS2010 and later let you build with other toolchains such as gcc, but you'd need an appropriate toolchain description in addition to the cross-compiler built by crosstool-ng). But you'll have a working g++-linux-gnu, which you can either run directly or using a Makefile.

NOTE: Building the cross-compiler takes a LONG time. osm0sis has provided a prebuilt gcc 4.8.1 here, along with his notes on building the cross-compiler (used to update this answer).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...