How to write GTK applications in Visual Studio c++ for Linux platform? - c++

I made c++ project for Linux platform in Visual Studio and connected to linux virtual machine with g++, gdb, gdbserver and libgtk-3-dev. But I can't compile program with gtk.h lib. What do I need to do for Visual Studio to detect gtk?

Visual C++ for Linux builds your application on the target Linux system. Therefore the GTK+ headers and libraries need only be present on the Linux target. However, if you want IntelliSense to work (and who wouldn't) the GTK+ headers need to be visible to Visual Studio on the Windows host. The easiest way to do this is to copy the headers onto the Windows host (put them in their own folder). The include path in Visual Studio's project settings must specify the Linux path for the GTK+ headers for g++ on the Linux target and the Windows path on the Windows host.
This question might give you some more information.
And, as you are using c++, you might like gtkmm which provides c++ bindings for GTK+.

Related

Windows Subsystem for Linux - Include path for Visual Studio 2019 IntelliSens

Apologies if this is trivial.
I am working on a C++ project using Windows Subsystem for Linux. There is no issue compiling and debugging the project, but IntelliSense does not see the libraries I have installed and gives me a lot of warnings/errors:
Where is the lib folder for Windows Subsystem for Linux?

visual studio 2017 linux c++ librt

I've read, I can use Visual Studio 2017 on Windows to develop C++ application with remotely debugging on a Linux machine. I like this idea because I'm familiair with VS2017 for C# on Windows applications.
For my new study, I need to develop on Linux but for example must develope applications which use shared memory via Posix. So I need to include the LIBRT library. But this one is specific for Linux, so if I need to use such kind of specific linux library's, could I then also use this VS2017 setup?
If how, how does that work because I did not find any information about it.
Thx
I encountered the same obstacle but for libcurl. What fixed it was adding gcc arguments in the Visual Studio linker. Right click the project and pick Properties->Linker->All Optptions->Additional Options and add the same parameter you would give to g++, in my case -lcurl. I have also tested it for -pthread.

Visual Studio 2017 C++ linux app, headers not copied to target

I have a VS 2017 C++ linux app which is deployed to the Bash on Windows linux subsytem in Windows 10. I have included header directories using the C++ project properties 'Additional Includes'. However when the project is compiled, the compiler complains that it cannot open header files. As the source files are being compiled on the target machine as opposed to locally, I assume the header files need to be copied there as well but what setting is required for this. Currently they are not being copied, they can be browsed to in the IDE however
Thanks
Tested on Visual Studio Community 2017 15.9.7 and Visual Studio Enterprise
2019 Preview 4.
Visual Studio needs to download all remote headers in your localmachine for correct behavior of intellisense.
New method 'rsync_ssh' doesn't download all headers. You can use old method .zip via sftp_ssh.
0. Add remote connection.
Tools->Options->Cross Platform->Connection Manager
1. Select your connection
Update from Tools->Options->Cross Platform->Connection Manager->Remote Headers Intellisense Manager.
Next click on Explore button.
2. C:\Users[YourUser]\AppData\Local\Microsoft\Linux\HeaderCache\1.0[IdNumber]
Rename the HeaderCache settings.xml.unused file to settings.xml
3. In the settings.xml file Change the syncMethod to sftp_ssh.
4. Update headers cache from Tools->Options->Cross Platform->Connection Manager->Remote Headers Intellisense Manager.
5. Enjoy.
Before
After
Visual C++ for Linux Development (VCLinux) doesn't copy headers to the remote (Linux) system that are not in the Visual Studio project.
VCLinux installs copies of most of the common Linux system headers (/usr/include etc.) on the Windows host so that IntelliSense can see them but the system headers for the Linux system must be present on the remote for your application to compile (with g++). System headers are on the include search path for g++ by default. And the VCLinux copies are on the Visual Studio IntelliSense include path by default. If you have had to specify Additional Includes it suggests that the headers you're interested in belong to some optional component which you'll probably have to explicitly install on the Linux remote.
It's worth remembering that Windows Subsystem for Linux (WSL) is still limited, i.e. it doesn't (yet) have everything you would find in a conventional Linux distro like Debian. And while grabbing the missing headers from somewhere could allow your application to compile it might to fail to link or run.
This might also be of interest: Linux header file not recognized in Visual Studio 2017 Linux Project

Visual Studio cross-compilation to Linux

Visual Studio 2015 has brought with itself a cross-platform support for native C++ projects. In this context cross-platform means Windows, Android and iOS.
New Visual Studio now officially supports CLang and GCC tool-chains along with its own compiler. However it doesn't support cross-compilation to Linux.
Which, in turn, means that one still have to maintain at least two different projects in different IDEs to get native library binaries for all major operating systems.
Is this possible to "cheat" on Visual Studio and enable Linux targeting by modifying parameters of native Android project and/or by modifying NDK installation?
After all, Visual Studio just invokes NDK tools through a command line...
Before Windows 10 Anniversary Upgrade it was possible to cross-compile to Linux from within VS with Visual C++ for Linux Development extension.
However, you still had to setup a Linux machine (either real one or VM) since this extension supports Remote build & debugging only.
Windows 10 Anniversary Upgrade has introduced Windows Subsystem for Linux, which:
lets developers run Linux environments -- including most command-line
tools, utilities, and applications -- directly on Windows, unmodified,
without the overhead of a virtual machine
Thanks to this great feature happy owners of Windows 10 can easily setup remote cross-compilation to their localhost.
You can get the details either in official Microsoft blog post or here.

Visual studio 2010 project for windows and linux

I'm trying to make a program that works on linux and windows.
I'm writing the program in visual studio in a windows environment.
So I wonder how I could compile my project from visual studio to linux.
The Microsoft C++ compiler is not capable of producing Linux executables.
You will need to use a more portable compiler for your Linux executables, e.g. gcc. Perhaps you may benefit from a cross-platform IDE like Code Blocks or Eclipse rather than Visual Studio.
You should try QT. It is pretty good framework for cross-platform development. The opensource version is free and very well maintained and has the LGPL license. That means you can sell your product as closed source but then you have to dynamically link to QT libraries.
You can use CMake. It will allow you to generate project/solution files for Visual Studio and Makefiles for Linux. This way, you can work using the native tool chain for a platform, while managing a single makefile. However, it's up to you to write portable code and to choose the appropriate libraries for your program to be truly portable.