Porting C++ application from Windows to GNU/Linux. - linux

I'm trying to port a computer game from windows to GNU/Linux. It uses Ogre3D,CEGUI, ogreogg and ogrenewt. As far as I know all dependencies work on GNU/Linux and in the game itself there is no ooze-specific code.
Here's the questions part:
Is there any easy way to port visual studio 2008 project to GNU/Linux tool-chain?
How do I manage dependencies? In Visual Studio, I'd just add them in property sheets or default directories. I assume on GNU/Linux autoconf and make take care of that, but in which way? Do I have to add each .cpp and .hppmanually or is there some way to automate things? How do I solve the problem of dependencies on different locations on different systems? I'd like to use Eclipse as my IDE under GNU/Linux.

As #pmr has noted, you are really looking for a build system. While the GNU Autotools (Automake, Autoconf, etc.) have traditionally been used, there are a lot of problems with these tools, and they have an incredibly steep learning curve. I would strongly suggest, instead, that you use CMake. CMake is somewhat of a meta build system in that CMake generates projects for a variety of build systems using the CMake project description; CMake, by default, generates a Makefile project from its project description, but it can also generate projects for Visual Studio, Xcode, KDevelop, and others. You may find the C++ Application Project Template and the C++ Library Project Template useful as examples of how to use the CMake build system. Tutorials and other introductory material about CMake may be found on the CMake Wiki, while the CMake Reference Manual gives detailed instructions for all the various commands that CMake supports (you will probably find ADD_EXECUTABLE, ADD_LIBRARY, TARGET_LINK_LIBRARIES, INCLUDE_DIRECTORIES, and LINK_DIRECTORIES to be the most useful of the commands that are available). Also, while I would strongly advise you to use CMake instead of Make, you may find my Makefile tutorial useful in the event you decide to use Make.

What you are essentially asking is: What is a good build system for GNU/Linux. There is no definitive answer to this problem. Make + autoconf are the standard way of doing things but you could be happier with cmake which has the benefit of being cross-plattform.

Related

Application deployment with 3rd-party dependencies for both Linux and Windows, using CMake and Conan

I'm working on a project, which targets both Windows and Linux (and possible in the future MacOS). It consists of some applications with several shared libraries. It is written in modern C++ and modern CMake. It also uses 3rd-party libraries like Qt, OpenCV, Boost, GraphicsMagick, samplerate, sndfile. Those dependencies are handled through Conan package manager. I'm building both on Linux (Ubuntu 18.04, GCC 8.1) and Windows (via WSL - also Ubuntu 18.04, MinGW-w64 8.1). I'm using fairly recent versions of 3rd-party libraries with custom built options (strictly speaking - different versions than available on Ubuntu's APT, e.g. Qt v5.11.3, or custom built of GraphicsMagick)
I'm using CPack. On Windows I'm building NSIS installer, but on Linux I would like to use DEB generator (may be other if needed). All of my targets (written apps and shared libs) have appropriate CMake's INSTALL configurations, so they are copied correctly into the generated installers (component based installation). The real problem comes with packaging of 3rd-party dependencies.
Problem
Strictly speaking, I have no idea, how to do it well using CMake+CPack+Conan, both on Linux and Windows. I've read a lot of articles and posts, but I'm stucked. I would like to have something, that automatically bundles into the installer all 3rd party libraries used by project with needed plugins and, what is the most important, with needed system/compiler libraries (libgomp, libstdc++ and so on).
Possible solution
To my surprise, on Windows, this task is fairly easy, because every DLL used by app (my libs, 3rd-party libs and system/compiler libs) needs to be located where executable is. I'm engaging Conan into this, by importing all used DLLs into bin directory. In the end, in most naive way of packaging, I will just copy the bin directory into the installer and it should work. But I'm not sure, if this approach is OK.
On Linux, things are more complicated. First, there is arleady a package manager. Unfortunately, libraries/compilers available there are too old for me (e.g. on APT there is only Qt 5.9.6 ) and are built using different compile options. So, the only way for me is to ship them with my software (like in Windows). There are also issues with searching for dynamic libraries by ld, RPATH handling and so on. At the moment, the only solution I see is to write something like 'launcher' for my app, which sets LD_LIBRARY_PATH before program starts. After that, in this case we can just copy bin or lib directory to the DEB installer and this should work. But still, I don't know if this is correct approach.
Other solutions
I've also looked into other solutions. One of them was BundleUtilities from CMake. It doesn't work for me. It has a lot of problems in recognizing, whether some library is system or local one. Especially in WSL, where it stucked in processing dependencies to USER32.dll, KERNEL32.dll. BundleUtilities in Windows worked for me only with MSYS, but in MSYS I've failed to compile some 3rd-party libraries (GraphicsMagicks via Conan) and that's the reason, why I'm using WSL.
Summary
I'm looking for good and verified method of packaging C++ projects with multiple apps, libs and shipped 3rd-party libs, both for Windows and Linux. How are you doing things like this? Are you just copying bin and/or lib dirs to the installers? How (in terms of CMake/CPack code) are you doing that? INSTALL(DIRECTORY ...), or similar? I'm not sure, but I think that this problem should be already solved in the industry. ;)
Thanks for all suggestions.
First, Conan is a package manager for development, not for distribution, that's why you didn't find an easy way to solve your problem. Second, most of discussions are made at Conan issue, including bugs and questions. There you will find a big community + Conan devs which are very helpful.
with needed system/compiler libraries
This is not part of Conan. Why you don't use static linkage for system libraries?
Talking about CPack, we have an open discussion about it usage with Conan: https://github.com/conan-io/conan/issues/5655
Please, join us.
I see few options for your case:
on package method, run self.copy and all dependencies from self.cpp_deps, which includes all libraries, so you can run Cpack
Use Conan deploy generator to deploy all artifacts, and using a hook you can run cpack or any other installer tool
Out friend SSE4 is writing a new blog post about Deployment + Conan, I think it can help you a lot. You can read a preview here.
Regards!

Is it possible to build native gdb for Linux-ARM on Linux-x86-64?

I'm trying to build a native ARM GDB for an ARM board to use. Since it lacks a lot of the tools GDB needs for compilation, I'm trying to build it on my x86 machine.
./configure --host=arm-linux-gnueabi --target=arm-linux-gnueabi && make
However, half way through the build process, it complains that "termcap library" is missing. I think it means it couldn't find an ARM version of the library for it to use. So, is there a possible workaround, or should I not bother with this approach and think of another way?
You should be able to do this for your "ARM board". You need to compile GDB library dependencies (e.g. the termcap library) and install them where the cross compiler can find them before you can build GDB. Without a more specific description about the cross compilation toolchain and board it's hard to give more specific advice that will be helpful to you.
I cross build GDB for several Linux targets for my ELLCC cross development tool project (http://ellcc.org). You do need a few libraries built for the target to do a build. In addition to the standard C library, I used libedit, zlib, expat, and ncurses.

Can I compile and run a linux app C++ source on Windows?

I have source code for a linux application. It seems I can compile it on windows with CygWin. My question is, after compilation, can I run it on Windows?
Depends totally on what APIs you use. If you stick to C standard library things, like <stdio.h>, <stdlib.h>, etc. then yes, you can just compile and run on either OS. Or for C++ apps, there is the Standard C++ Library, which any OS / development environment should provide.
If you use any OS-specific APIs, then of course it will not be compatible with another OS. There are libraries however, like APR that try to abstract out the OS-specific bits.
From a casual glance at the code you've linked to, it appears to not use any OS-specific APIs. However:
Note that this code requires the Gnu Scientific Library, http://www.gnu.org/software/gsl/
you'll need to get that library installed as well.
The simple answer is yes; if you can compile a Linux application with Cygwin, then the compiled application will run on windows. Cygwin provides windows implementations of many unix system functions and libraries.
Cygwin/mingw(http://www.mingw.org/) should have most of the tools you need to build the binary. Once the build succeeds, you can run the binary (only) on windows.

which suits linux ? GNU make vs cmake vs codeblocks vs qmake

In front of me some different Technologies and I'm confused between them.
GNU make, CMAKE, Qmake, Code::blocks methodology
Code::Blocks uses a custom build system, which stores its information in XML-based project files, but can optionally use external makefiles **says WIKI**
1- What's the difference between CMAKE and GNU MAKE ?
2- If I'm planning for long term relationship with linux what is the best for that ?
3- If I needed to cross-platform some apps, will I need the same technique ?
CMake generates platform specific make files. So on Linux, it wil generate files for gnu make, on windows it can generate Visual Studio solutions.
There are some other good options to consider like scons and waf, they are both Python based, cross platform, and are much more pleasant to work with than GNU Make.
CMake is a cross-platform wrapper around more traditional build systems. like make for linux and Visual Studio Solutions for windows.
"One nice feature of CMake is the ability to do out of source builds. That means you can make all your .o files and even the binary executables without cluttering up your source tree."
I found this tutorial very helpful.

anyway to write dlls in linux?

Is there anyway to write dlls in linux?
Do I have to install windows to write dlls in linux? Right now one of my courses requires me to write a dll for this.
You should take a look into 'shared libraries'
http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html
Lots of folks are getting near the right answer but not providing it: gcc can generate win32 PE/COFF files without problem, and of course can always build as a cross compiler on any platform it can target. The binutils port targets windows .exe and .dll files natively, and there's a "dlltool" utility for handling the edge cases where Unix and Windows linkage metaphors are different.
Additionally, the "mingw32" project provides a set of link libraries and header files for building C applications against the win32 API. These likewise install just fine on any Unix.
Here's a site I turned up after a quick google with instructions for building the toolchain.
Not really. Building any kind of executable intended for OS "A" while using OS "B" is a process commonly known as cross-compilation. In this partciluar case, you would need a cross-compiler running on Linux, but targetting Windows. I don't know any vendor selling such a product.

Resources