franneck94 / Vscode-C-Cpp-Runner

🚀 Compile, run and debug single or multiple C/C++ files with ease. 🚀
MIT License
53 stars 14 forks source link

Specify additional libraries for MSVC linker #158

Closed vsl-iil closed 2 months ago

vsl-iil commented 2 months ago

Hello. I'm trying to use GetUserName function from Windows API. I use C/C++ Runner and I have it set up to work with MSVC. However, I get an error with this particular program:

username.obj : error LNK2019: unresolved external symbol __imp_GetUserNameA referenced in function main
.\build\Debug\outDebug.exe : fatal error LNK1120: 1 unresolved externals

I assume what I need to do is link against Advapi32.lib library, however, when I specify it in Linker Args in user settings (with and without preceding /l), I still get the same error. I assume linker args are not applied to MSVC?

The code in question:

char name_buf[UNLEN+1];
DWORD buflen = UNLEN+1;

GetUserName((TCHAR*)name_buf, &buflen);
vsl-iil commented 2 months ago

I added the Advapi32.lib argument to Workspace setting and it worked.

franneck94 commented 2 months ago

Yes always use the workspace and not global settings