14

I am using Visual Studio 2008 C++ project (Visa 32 bit).

I have the following #include directive in my source code.

#include <example/header.h>

In my include path I specify the parent directory of 'example', i.e.

C:/.../include

where the full path to the header looks like

C:/.../include/example/header.h

However, 'example' is a symbolic link (A '.lnk' created via file explorer 'new shortcut'). I get the following error

c:...\foo.cpp(37) : fatal error C1083: Cannot open include file: 'example/header.h': No such file or directory

If I replace the symbolic link with the actual directory, the project will compile correctly. For practical reasons I need it to be a symbolic link. Is there anyway to make the Visual Studio pre-processor follow the link?

Akusete
  • 10,704
  • 7
  • 57
  • 73
  • 1
    To make your question description a bit more clear, you might want to change 'example.h' to 'header.h' or something, as you later reference 'example' so at first it's a little hard to follow. – Cam Aug 16 '10 at 05:00
  • @Cam: Done. I've tried to re-word the question to make it more legible. – Akusete Aug 16 '10 at 05:08
  • Much better ;) ...If you browse to `example` from your desktop, does it work properly? Also, are you using an actual "symbolic link", or are you using a "junction"? (that last question may seem pointless/obvious, but I just want to be sure) – Cam Aug 16 '10 at 05:19
  • @Cam: Viewing the symbolic link through the file explorer works correctly. The link is a symbolic link (.lnk), I did not even know what a junction was until I looked it up just now :). – Akusete Aug 16 '10 at 05:22
  • 1
    @Akusete: I just tested and it seems to work fine for me. How did you create the symbolic link? – Cam Aug 16 '10 at 05:38
  • @Cam: Initially it was through a cygwin script 'using ln', but when I encountered the problem the first thing I did was to re-create the link using the file explorer 'new shortcut' method. Thanks for the confirmation that the links should work. I'll double check everything then, it narrows down the search. – Akusete Aug 16 '10 at 05:40
  • @Akusete: Check my answer below - what you're creating is actually *not* a symbolic link, but rather a shortcut. Symbolic links do not have the .ink extension. – Cam Aug 16 '10 at 05:42

3 Answers3

10

The link is a symbolic link (.lnk)

Are you sure you're not creating a shortcut? Shortcuts work on a higher level than symbolic links and mean nothing to applications.

Conversely, symbolic links (if properly created) should work fine with any application that reads/writes to files/folders.

For more details, you may wish to consider reading this article about symbolic links, which explains how you can create a symbolic link using mklink.

Here's a helpful snippet from a comment on that article by "Bernard Kerckenaere":

  • shortcut: on the operating system level (to applications who wish to read/write the link, it’s just a meaningless file)

  • soft link (or symbolic link): like a shortcut, but on the filesystem level (applications reading/writing the link, will actually read/write the file linked to) ... this will work across partitions, or drives

  • hard link: only for files, what happens is that there are multiple file entries that point to the same physical data, when you delete one entry, the other will still work, the data won’t be gone until all entries are deleted (if with a soft link you delete the original directory, the link won’t work anymore!) -> you can obviously only create hard links to a file on the same partition

What you want to create is a symbolic link which you can do with the /D parameter using mlink.

Cam
  • 14,930
  • 16
  • 77
  • 128
  • Ahh... I don't frequent windows much for development. I'm surprised 'ln -s', in cygwin created a '.lnk' file – Akusete Aug 16 '10 at 05:54
  • I am porting a linux project to windows and the script generated header file links using 'ln -s', which on cygwin created shortcuts instead of actual symbolic links – Akusete Aug 16 '10 at 05:59
  • 1
    @Akusete: Ah - that's annoying. I'm not incredibly familiar with *nix development or cygwin (although I'm working on fixing that!), but I don't think you can easily create a symbolic link through cygwin. Can you just replace the ln -s instances with calls to mklink? – Cam Aug 16 '10 at 06:06
1

.lnk is not symbolic link, it is shortcut file for Explorer. To create hard link, use

fsutil hardlink create link_name file_name

On Vista, there is mklink utility to create symbolic links.

alxx
  • 9,897
  • 4
  • 26
  • 41
0

Older versions of Visual Studio are a bit finicky when it comes to symlinks. Hard links on files using the \H parameter hardly ever work, but symlinking entire directories using \D is usually fine. Afterwards, you might need to remove and re-add the folder from and to your project, though.

Protector one
  • 6,926
  • 5
  • 62
  • 86