2

I'm porting C/C++ code from Unix to Windows that makes use of the symlink() function.

From what I understand, recent Windows file systems have a equivalent of symbolic links.

What would be the best / most portable way replace the symlink() function, so the same code works on both platforms ?

Gene Vincent
  • 5,237
  • 9
  • 50
  • 86

3 Answers3

2

The underlying technology on Windows is called Junction points. The Boost Filesystem Library is cross platform and can make symlinks:

http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/reference.html#create_symlink

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • @Timo Geusch: Thanks for updating the link to the latest version - I was just on the way when you made your edit. – Anders Abel Jun 24 '11 at 19:46
2

Since Windows Vista there's a function to create true symbolic links: CreateSymbolicLink

Note that Junctions as mentioned in the other answers only support directories, and even with the newer feature, windows symbolic links require you to specify whether the target is a directory or a file. So you won't necessarily be able to get a trivial "drop-in replacement" symlink() function.

Random832
  • 37,415
  • 3
  • 44
  • 63
0

Junctions seem to be the answer from similar questions .

Community
  • 1
  • 1
Bradley Swain
  • 804
  • 5
  • 12