Peter H
Peter H

Reputation: 901

VC_Linux - Visual Studio c++ Linux Cross Platform build for Raspberry Pi - Library issue

I'm experimenting with Visual studio's VC_Linux for Raspberry Pi3 in the hope of being able to compile and debug code.

I'm attempting to code a UDP client and server on the Pi.

Out of the Box VCLinux worked great for a simple hello world project... but as soon as I attempt to reference source files from the Pi that exist in the usr/include of the Pi folder Visual Studio starts to complain about source files not existing or that they cannot be found.

For example I need the socket.h file to build a UDP client/Server. In the Pi this can be found in

usr\include\asm-generic\socket.h

I copied the whole usr\include file from the Pi to my Windows machine (Renaming it PI_Source so the include folder is not the same as the default one of "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include"). I attempted to add the copied PI_Source folder to my include directories and source directories within the project properties.

VC++ Directories

Attempting to build the following file results in an error...with Visual Studio complaining that it can't find socket.h and sockios.h.

#include <cstdio>
#include <asm-generic\socket.h>
#include <asm-generic\sockios.h>

int main()
{
    printf("hello from Pi_Testing!\n");
    return 0;
}

Build Error

How do I get Visual studio to successfully build with the source files and directories linked properly?

Am I putting the Pi Include folder in the wrong Path? Does it need to be placed under
*C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include*
Any other recommendations/suggestions for me to try?

Upvotes: 1

Views: 1388

Answers (1)

stanthomas
stanthomas

Reputation: 1181

You're using the wrong path delimiter for your header files, on Linux it's / and on Windows it's \. Fortunately Visual C++ accepts both forms so cross-platform code should use /.

More generally. You will normally specify include paths in the C/C++ General page of the project settings not VC++ Directories.

The include paths that you specify in Additional Include Directories of the C/C++ General page serve two purposes:

  1. a path on the remote Linux system, e.g. /usr/include/asm-generic to tell g++ where to look for the header during compilation

  2. a path on the Windows host to tell VS where to find the header for IntelliSense

In VCLinux 1.0.5 you need to specify both. With relative paths this might result in the same path being specified twice.

/usr/include is searched by g++ by default and VCLinux supplies copies of headers for the standard C++ runtime for IntelliSense so you don't normally need to add anything to the project settings for these. However the headers you want are missing from the VCLinux distribution and, although your source will compile just fine, the header(s) will not be known to IntelliSense. So yes, put the header somewhere on your Windows system, anywhere is good, and specify the Windows path, just once, in the project settings.

Upvotes: 1

Related Questions