views:

28

answers:

2

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?

+3  A: 

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
Ahh... I don't frequent windows much for development. I'm surprised 'ln -s', in cygwin created a '.lnk' file
Akusete
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
@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
@Cam: I've just done that now... it works like a charm.
Akusete
+1  A: 

.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