onkami
onkami

Reputation: 9421

How to set up cross platform compliation for C++ (NetBeans in win7 and make in linux)

I would like to set up a gcc C++ project using my preferred editro NetBeans (since it works with gcc), that would depend on some external libraries. I want it to compile in NetBeans with gcc chain, and in production - using command line make under linux. Preferably, first create project in NetBeans and then modify something to accept it in Linux.

The libraries will be the same but located in different folders, so I need to separate include pathes for these, and during compile time correct pathes must be picked.

Also, I might need to use minor amount of conditional compilation, as under windows and linux some #include directives might or might not contain library sub-pathes.

Is there any useful guide how to make this happen?

Upvotes: 1

Views: 1692

Answers (1)

jlandercy
jlandercy

Reputation: 11012

Assuming you are developping with Netbeans on Win7 and you have a Linux machine (lets call it a server) accessible by TCP/IP with all packages proprely installed (gcc and you program depedencies).

You need to:

  • Add a Build Host in Netbeans Services and setup the ssh connection (you server needs deamon sshd active of course). Netbeans will seek for a toolchain. If everything worked out: this is your remote build host;
  • If you have all your packages installed on your linux server (I mean installed form the package manager), sources will be located in /usr/include and libraries in /usr/lib;
  • In your project properties, define a new profiles for your server application (choosing the proper build host) and resolve dependecies.

Then, when compiling for Win7 target use default profiles Netbeans created for you (build host is localhost) and when compiling for Linux target use new profiles you created (build host is your linux server).

To minimize conditional pre-porcessor codes when including, you just need to use relative paths and keep on Win7 the same file hierarchy for your dependencies that your linux server has.

Additionnaly, you can run on linux server development tools such has gprof and valgrind to check your work.

This should work easily.

Upvotes: 2

Related Questions