17

How do I create a soft link programmatically in C/C++? link() system call in freebsd will create a hard link.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Professor_Chaos
  • 323
  • 1
  • 2
  • 6

3 Answers3

27

The system call you want is symlink(2).

#include <unistd.h>

int symlink(const char  *name1, const char *name2);

A symbolic link name2 is created to name1

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
7

You can call symlink()

int symlink(const char* name1,  const char* name2);

A symbolic link name2 is created to name1 (name2 is the name of the file created, name1 is the string used in creating the symbolic link). Either name may be an arbitrary path name; the files need not be on the same file system.

Community
  • 1
  • 1
SSC
  • 1,311
  • 5
  • 18
  • 29
1

In C++17, call std::filesystem::create_symlink.

Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56