-
November 4th, 2017, 05:54 AM
#1
[RESOLVED] Does not recognize CreateSymbolicLink function
Hello guys,
i wanted to use the CreateSymbolicLink function of WinAPI.
Here is my code:
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int _tmain(int argc, LPTSTR argv[]) {
if (argc != 3) {
_ftprintf(stderr, _T("Usage: symhard srcfile destfile"));
return EXIT_FAILURE;
}
if(!CreateSymbolicLink(argv[2], argv[1], SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
_ftprintf(stdout, _T("Creating symboliclink failed: %lx"), GetLastError());
return 1;
}
return 0;
}
I'm using MSYS2 and clang version 5.0.0:
Code:
clang -Wall -Werror -pedantic -std=c99 -c symbolic_vs_hardlink.c
I always get the following output:
Code:
$ clang -Wall -Werror -pedantic -std=c99 -c symboliclink.c
symboliclink.c:12:6: error: implicit declaration of function 'CreateSymbolicLink' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if(!CreateSymbolicLink(argv[2], argv[1], SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
^
symboliclink.c:12:43: error: use of undeclared identifier 'SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE'
if(!CreateSymbolicLink(argv[2], argv[1], SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
^
2 errors generated.
It seems it does not know of the CreateSymbolicLink function nor the constant.
When trying the same code with Visual Studio 2017 it works and it also finds the function.
What am I doing wrong here?
Last edited by 2kaud; November 4th, 2017 at 05:59 AM.
-
November 4th, 2017, 06:00 AM
#2
Re: Does not recognize CreateSymbolicLink function
Why can't I edit my post? Here is the well formated code:
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int _tmain(int argc, LPTSTR argv[]) {
if (argc != 3) {
_ftprintf(stderr, _T("Usage: symhard srcfile destfile"));
return EXIT_FAILURE;
}
if(!CreateSymbolicLink(argv[2], argv[1], SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
_ftprintf(stdout, _T("Creating symboliclink failed: %lx"), GetLastError());
return 1;
}
return 0;
}
-
November 4th, 2017, 06:04 AM
#3
Re: Does not recognize CreateSymbolicLink function
You can't edit the post as you need a certain number of posts (10?) before this facility is enabled. I'd edited your original post for this.
Sorry I can't help you as I don't use clang, just VS.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 4th, 2017, 12:52 PM
#4
Re: Does not recognize CreateSymbolicLink function
If anybody is interested in the solution:
I had to modify _WIN32_WINNT. After adding
Code:
#define _WIN32_WINNT 0x600
before including the windows header file, it works!
The function is only available in Vista+ and VS compiler seems to add this defines automatically.
https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
-
November 4th, 2017, 03:59 PM
#5
Re: [RESOLVED] Does not recognize CreateSymbolicLink function
Glad you have resolved your problem!
So I mark this thread as resolved!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|